XNA Game-Themed CS1 Examples (XGC1)

Release 2.0 (XNA V3.1)

Topic: Topic.4.DecisionStructures
Example: Ex_10.LogicalAnd

Decision Statements: Logical AND Operator

Need (library reference):



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:

The game behaves in a manner that is identical to the what was described for the previous tutorial, with a couple of new features:

  1. It is possible to 'win' the game.  The player can win the game by bouncing the ball of the paddles more than BOUNCES_NEEDED_TO_WIN times (in a row, without missing it), and missing the ball less than MAX_BALLS_MISSED_TO_WIN times.  However, once the player has bounced the ball BOUNCES_NEEDED_TO_WIN times (in a row, without missing it), then further bounces will decrease the number of misses, until the player wins.

  2. When the player wins, the game displays a "You've Won!" screen, which looks like:

    Once the player has won, the game stops updating (i.e., the ball & paddles stop moving), and almost all user input is disabled.

  3. At any time (before, or after winning), the player may press the 'A' button, and restart the game

Let's examine the source code, feature by feature

2. Winning the game


  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.

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.