XNA Game-Themed CS1 Examples (XGC1)

Release 2.0 (XNA V3.1)

Topic: Topic.5.RepetitionStructures
Example: Ex_20.NestedForWhileLoops

Repetition: Nesting Different Loops, If Statements



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:

By using the left thumbstick, you can adjust both the horizontal space between the circles, and the vertical space between the circles.  You'll notice that this program is extremely similar to the previous tutorial's program, except that the rows alternate which image they use (soccer ball or basket ball), and that the bottom-most row and left-most column are no longer directly on the bottom/left edges of the screen.

2. Examining The Program:

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


  1. Start from a blank starter project (1000.201, if you need it), and re-do the code from memory as much as possible.  On your first try, do what you can, and keep the above code open so that when you get stuck, you can quickly look up what you forgot (and that after you finish a line, so that you can compare your line to the 'correct' line).  On the next try, do the same thing, but try to use the finished code less.  Repeat this until you can type everything, without refering the tutorial's code.
  2. Practicing With Nested Conditional Statements
    For this exercise, you should use the same project that was explained in the above tutorial.
    See if you can modify the provided code so that the first column is all basketballs, then the second column is soccer balls, then the columns continue to alternate.

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.