Project 5

Revision: 3/31/2008 7:42:59 AM

1214 Spring 08, Professor Wartell

Due: Sunday 4/13/08 11:00PM

Assignment: In this exercise, you write the first part of a simple game. On the class website is the partial source code for this game in Project5.zip. Additionally, a working example of the final result for Project 5 is provided as Project5.exe.

The program uses ASCII characters for all drawing as shown below. In the middle of the screen is an ASCII smiley face. The game screen has a border made of # characters.

The user can enter the following single letter commands: r, l, u, d, q. These stand for ‘right’, ‘left’, ‘up’, ‘down’ and ‘quit’. The movement commands move the face in the corresponding direction. ‘q’ quits the program. Additionally, the movement commands are always immediately followed by an integer. The integer indicates the face should move that number of steps in the indicated direction. So entering ‘r10’ would cause the face to make 10 steps to the right. Experiment with Project5.exe to better understand the commands.

If the face runs into a # character it stops moving and registers a ‘crash’.

The number of total crashes that have occurred is displayed at the bottom of the screen.

Note, you must test for crashes at every step. So for the command r10, you must test for a crash at each of the 10 steps. Also stop executing the current command if a crash occurs. Play with Project5.exe to see the expected behavior. (To detect crashes you must use the function, getCharacter, see below.)

How to Draw Stuff: The code in Project5.zip contains a file Screen.cpp that provides several functions for drawing characters to the screen. These include:

  • void clear();
  • void display();
  • void setRow(int x, int y, std::string row);
  • void setCharacter(int x, int y, char c);
  • char getCharacter(int x, int y);

Screen.h includes a brief description of what each function does. (You do not need to worry about how Screen.cpp implements these functions). Briefly, the screen is treated as a grid where each grid location, given by an x and y coordinate, contains an ASCII character. setRow, setCharacter and clear update a memory buffer that stores the grid of characters and displaycopies the buffer contents to the program’s window.

The file main.cpp shows the basic strategy in using these functions. The basic structure is as follows:

while (!gameOver)

{

clear(); // this function clears the screen

/*

here you use the setRow and setCharacter functions to place characters in screen
buffer and perform any logic needed for drawing the objects in the game

*/

display(); // this function copies the screen buffer to the display

/*
here you output simple messages using standard cout methods

*/

/*

Next, if your program needs to get another command from the user, you prompt the
user fora new command and process that command

*/

}

Study main.cpp carefully since it serves as a template for your assignment.

Turnin: You should modify the contents of Project5.zip and then re-Zip the folder and turn in that re-Zipped folder with you additions. This folder must contain:

  • Project 5.sln - the MSVS 2005 solution file
  • Project 5.vcproj - the MSVS 2005 project file
  • all the .cpp and .h files –
  • Project 5.txt – an optional text file for any additional comments

The single .zip is uploaded to Blackboard.

NOTE: Be sure to adhere to the University’s Policy on Academic Integrity as discussed in class. Programming assignments are to be written individually and submitted programs must be the result of your own efforts.