XNA Game-Themed CS1 Examples ( XGC1 )

Release 2.0 (XNA V3.1)

Topic: Topic.5.RepetitionStructures
Example: Ex_10.ZapGameForLoop

Zap Game: For Loop



1. Obtain the example code

Download and unzip the zip file and you will see an ExampleProgram folder. Open the ExampleProgram folder, the EXE folder contains the compiled program and you can double click on the .sln file to work with the source code.

When the game starts, you'll see a screen that looks similar to this:

This version of the 'zap' game looks and plays identically to the prior version, which was explained in the 160 tutorial .

There are only two differences, code-wise, between this version and the prior version: this version uses a for loop, instead of a while loop, and this one counts slightly differently (instead of adding 1f to HeroBeam.X each time, it use a separate counter variable, and copies that variable into HeroBeam.X)

2. Examining The Program:

Let's examine the C# source code that produces the behavior we see on-screen


  1. Go back to the 160 tutorial, and redo those exercises, using for loop(s).

Project home page : The Game-Themed Introductory Programming Project.
Kelvin Sung
Computing and Software Systems
University of Washington, Bothell
Michael Panitz
Business And Information Technology
Cascadia Community College

Microsoft Logo This work is supported in part by a grant from Microsoft Research under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871 and 16531.