XNA Game-Themed CS1 Examples ( XGC1 )

Release 2.0 (XNA V3.1)
2/8/2010

Topic: Topic.3.ModulesAndFunctions
Example: Ex_8.FormulaWithFunctions

(Re-)Implementing A Game Using Functions


References:

Goals:



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 program is functionally equivalent to 2000.700, so you should read the description for that program before you start in on this tutorial.  You are strongly encouraged to review the material from that tutorial, so that you've comfortable with the concepts used in that tutorial, and the details of the code presented in that tutorial, before attempting to do this tutorial.


2. Examining The Program:

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


FURTHER EXERCISES:

  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. Adding Parameters To A Function
    For this exercise, you should use the same project that was explained in the above tutorial.
    Right now, ComputeFutureValue works, and works well.  However, it assumes that we're going to be storing the present value, rate and number of years in instance variables.  Change this function so that it takes (as parameters) the present value, rate and number of years, and then does the same calculation that it's currently doing.  In order to make this work, you'll need to adjust the parts of the program that call this function, too.

  3. Adding Parameters To A Function
    For this exercise, you should use the same project that was explained in the above tutorial.
    Add two more rectangles to the program, so that you can show how much money you'll have after m_Year years (this is currently being done, in the above tutorial), then m_Year +10 years, and then m_Year + 20 years, with three separate rectangles


Project home page : The Game-Themed Introductory Programming Project.
Kelvin Sung
Computing and Software Systems
University of Washington, Bothell
ksung@u.washington.edu
Michael Panitz
Business And Information Technology
Cascadia Community College
mpanitz@cascadia.eduu

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.
2/8/2010