|XNA Game-Themed CS1 Examples ( XGC1 )|
Release 2.0 (XNA V3.1)
1. Obtain the example code
In this tutorial (and the next), we will examine Input and Output in an XNACS1Lib-based video game program. Input and Output are often abbreviated as 'I/O'. 'Input' refers to any data (information) that the computer program receives (i.e., data that is sent "in" to the program, from the program's point of view).. Examples of input might include a button being pushed on the XBox360 controller, a key being pressed on the computer's keyboard, data that the program reads from a file stored on the hard drive, or data received over a network from another computer . 'Output' refers to any data (information) that the program sends back to the rest of the world. Examples of output might include a textual message on printed the screen (including things like the player's current score), shapes and pictures on the screen, information saved to a file (stored on the hard drive), or sending data over a network to another computer. Keep in mind that when we use the term 'computer', we mean anything that functions like a computer - your desktop PC, your laptop, your XBox, and even items like your mobile phone, etc.
Many textbooks focus on 'Console' I/O. Console I/O programs mostly print out messages to a 'console' (or 'command prompt', or 'command interpreter', etc), then wait for you to type input something, then do something with that input, then restart the process by printing out a message. While console I/O looks primitive, it has a lot of advantages over programs that are based on a Graphical User Interface (GUI - a program that has windows, buttons, etc):
Console IO is extremely easy to do
You don't need to write a lot of code to do this, nor do you need to understand very complicated concepts to make it work
quick to do
Many simple messages can be printed with only a single line of code.
It allows someone who's new to programming to immediately move past the I/O issues, and move on to actually learning how to work with the core computational concepts that make programming useful.
In contrast, most GUI based programs require substantial amounts of overhead - windows need to be created, text needs to be written onto the windows to label the various buttons, controls, and widgets that the user will interact with, etc. Even web applications have substantial overhead when one's goal is to learn computer programming. Web applications commonly require at least a basic understanding of (x)HTML (and maybe CSS, too), forms and other means of sending data between the browser and server, basic SQL (or some other storage technology), etc, etc. In comparison, the primitive 'print a message, get user input, repeat' loop of console I/O is quick and easy to use. For more information about I/O, please consult your textbook, and/or your instructor.
In these tutorials, we'll be looking at creating graphical, interactive programs, including video game programs. For right now, we're going to look at how to create some output that is similar to the console output that your textbook is focusing on. In future tutorials, we'll look at how to create graphical output (drawing rectangles and circles on the screen, including how to put an image from a file over a circle/rectangle), and more advanced input (for example, how to create a game that reacts to buttons being pushed, or a joystick/thumbstick being moved).
Let's look at the C# source code that produces the messages at the top and bottom of the screen. Since the only thing that this program does is print a message to the screen, we don't really need to add anything to the Initialize step, just to the Update step .
protected override void InitializeWorld()
World.SetWorldCoordinate(new Vector2 (0,0), 100.0f);
UpdateWorld will check to see if the program should exit, and if not, then it will print a message to the screen:
2 3: XNA Rocks!"
then you would only see 45 67 89: So do you! at the top of the screen, since the results of the first EchoToTopStatus would replaced by the results of the second EchoToTopStatus .
FURTHER EXERCISES::Now that you've read through this tutorial and the provided example code (in detail!), here are some exercises for you to try on your own. Remember that learning to program is much like learning a new spoken, human language - you should try out new stuff on your own, and challenge yourself to do things that aren't even listed here. After all - your objective is not to memorize everything that you might possibly want to say in this new language, but instead, to learn how to say whatever you want in the new language by putting together different pieces.
|Error:||Compiler Message:||Your Interpretation:|
|In UpdateWorld, remove the starting and/or ending curly brace|
|Right after the InitializeWorld method, add an EXTRA close curly brace|
In UpdateWorld, on the line that has EchoToTopStatus, remove the parentheses ?
the ( and /or )
|In UpdateWorld, on the line that has EchoToTop/BottomStatus, try changing the capitalization of EchoToTopStatus|
|In UpdateWorld, remove a semi-colon|
|Try at least three more things, on your own:|
: The Game-Themed Introductory Programming Project.
Computing and Software Systems
University of Washington, Bothell
Business And Information Technology Cascadia Community College email@example.com
|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.|