Introduction to Computer Science I by James Tam | Return to the course web page |
Love or hate it Star Wars1 has had an undeniable impact on the movie industry by creating the tradition of the "summer block buster". The movie begins with a rebel ship carrying the plans for the "Death Star" (a mobile base ship capable of destroying whole planets) being boarded by the infamous Darth Vader. Through a complicated series of events the young farm boy, Luke Skywalker, becomes involved in the plan to destroy the Death Star. The movie culminates with Luke making a desperate strafing run at the only vulnerable location on the Death Star. For those who want to read more Star Wars trivia you can go to the following link (point number 3 almost rivals the "Get a life!" comment by William Shatner). The information used to create this introduction comes largely from the Internet Movie Database (http://www.imdb.com/title/tt0076759/). |
Figure 1: The equatorial trench, the scene of your game! |
Figure 2: The Death Star ("That's no moon!"). |
To win the game the player must successfully fly Luke's X-wing fighter (represented aptly enough by the upper case 'X' character) in a strafing attack run on the exhaust vent (represented by the 'v'). Each square of the equatorial trench is bounded above, below and to the left and right by lines. Solid walls are represented by the '*' character, open areas by the space character and the tie fighter by the upper case 'H' (JT: don't tie fighters looking like flying H's to you?) Although the images show a version of the game with three tie fighters you only have to implement a game with only a single tie fighter. The player loses the game if either Luke's ship has been destroyed (by crashing into the tie fighter or the walls) or if he misses the vent (the ship reaches the 20th column (marked by the 'K' at top right of Figure 3).
The trench will be represented by a 15x20 two-dimensional character array (rows 6 - 10 in Figure 3). The game starts out by initializing the array to the default starting character values and displaying onscreen a brief introductory message about the game. After that the game will run on a turn based fashion until the user decides to quit (i.e., selects 'q' at the main menu) or if the lose or win game conditions have been met. Each turn will be divided into a number of sub-turns:
Figure 3: A screenshot of Star Wars: The text arcade game. |
| |||||||||||||||||||||
| |||||||||||||||||||||
| |||||||||||||||||||||
| |||||||||||||||||||||
When the player selects the 'f' option it means that he or she does not want Luke to maneuver his ship and just wants it to fly straight ahead. The X-wing fighter will automatically move one square left to right in the trench regardless of whether the player chooses to maneuver the ship or not (you can't just stop a high speed fighter in mid-flight). You will 'move' Luke's ship by clearing the previous position and marking the destination square with the 'X' character (see Table 1) below: | |||||||||||||||||||||
|
| ||||||||||||||||||||
Table 1A: Before selecting option 'f''. | Table 1B: After selecting option 'f''. | ||||||||||||||||||||
Selecting option 'q' will end the game. The program will continue looping until either the player selects this option or until Luke's ship has reached the 20th column. When the latter occurs the game simply ends - you don't need to check for the win game condition in this version of the game. If Luke steers his ship into the occupied squares: '*', 'H' or 'v' then the previous character will be overwritten by the 'X'. In this version the lose game condition doesn't occur either. When Luke's ship moves off of this square then it will be set to a space so it looks like his ship has 'cleared' a part of the Death Star. | |||||||||||||||||||||
|
You must however implement a hidden 'cheat' option that won't be shown in the list of available functions but it will be invoked if 'C' or 'c' is entered (whereby the cheat menu, as described below, will be displayed onscreen). | ||||||||||||||||||||
| |||||||||||||||||||||
| |||||||||||||||||||||
| |||||||||||||||||||||
| |||||||||||||||||||||
Only a few of the functions of the cheat menu will actually work in this version. The toggle for the debugging messages will turn on or off the display of debugging messages for this version. The exact content of the messages is up to your discretion but as the name implies programmers will typically show information such as function or procedure calls, or the current values of variables at different points in a program in order to help them debug their program. (See the executable in the assignment directory for example messages). The only other option that needs to be functional for this version is the ability to quit the cheat menu.. Entering 'Q' or 'q' at the cheat menu will 'use up' the player's turn i.e., the tie fighter will again move and the updated state of the trench will be shown onscreen. Adding the 'm' option will be required in the more advanced versions of the game (higher grade levels) so that your marker can quickly determine if your program is working properly but is not necessary in this simple version. |
'r' : Move's Luke's ship 'up' the screen e.g., from row 9 to row 8. 'v': Move's Luke's ship 'down' the screen e.g., from row 6 to row 7. In both cases the ship will still move forward one square e.g., column 1 to column 2.
1 2 3 4 H 6 7 8 9 Table 2: The tie-fighters can move onto any adjacent square within the trench.
Figure 4: The game is over (lost) when Luke reaches the far column.
Figure 5: The game is won when Luke reaches the exhaust vent.
Figure 6A: Before the collision. Figure 6B: A tie fighter has hit the wall the of the trench.
Figure 6: Luke's ship has hit a tie-fighter!
D level assignment
The student has invested considerable work in the assignment and the code compiles but it doesn't fulfill any of the above requirements.
D- level assignment
The student has invested considerable work in the assignment but it doesn't compile.
As was the case with the previous assignment you need to break this fairly large problem down into some manageable parts. Here's an example of how you can do this when you are writing the full version of the code for main loop (it runs until the game is lost or the user quits the game):
- Move the tie fighter. Check for wall and ship collisions..
- Display the current state of the trench
- Display the main menu to the user
- Get the user's selection for the main menu - your program should be able to deal with invalid selections.
- Process the user's menu selection
- R: Update the coordinates for the X-wing fighter to move the ship 'up'.
- F: Update the coordinates for the X-wing fighter to move the ship straight ahead.
- V: Update the coordinates for the X-wing fighter to move the ship 'down'.
- C: Display the cheat menu and process the user's selection for the cheat menu in a fashion similar to processing his or her commands for the main menu.
- Check for collisions and the win/lose game conditions.
1 Star Wars is © Lucasfilm Ltd. References to either the this trademark or the inclusion of images from the movies are for education fair use only and are not meant as a copy write challenge.