Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 6 (Worth 6%)

New concepts to be applied in this assignment

  1. Two dimensional arrays
  2. Implementing a solution for a problem with a higher level of difficulty.

Introduction

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/).  

Assignment description

For this assignment you are to implement a text-based Star Wars arcade game.  This game will re-create the scene where Luke makes a strafing run in the equatorial trench (shown in Figure 1A) of the Death Star's (shown in Figure 1B) one vulnerable location, the exhaust vent.  If he can score a direct hit then the explosion will set off a chain reaction that will destroy the entire base.  However he only has one attempt to make his attack and if he is destroyed or if he misses/over flies the vent then all is lost because the Death Star will destroy the rebel base in a single volley.  The situation is made even more desperate as Luke faces a tie-fighter, which is flown by Darth Vader himself!

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:

  1. Move the tie fighter.
  2. Display the trench.
  3. Display the main menu.
  4. Move Luke's ship.
  5. Check the game status, determine if the player has won or lost the game and set the appropriate flag.
  6. If the player has won or lost the game then an appropriate concluding message will be displayed along with the final state of the trench and the program will end.  If the player opts to quit the game early, then neither the win game nor lose game message will appear and the program will simply end.  If the player doesn't choose to quit the game and if the game hasn't been won or lost,  then the program will return to step #1 until one of the end game conditions has been met.
Figure 3: A screenshot of Star Wars: The text arcade game.

Grades for working assignments:

Basic assignment: C

Extra features: 

  1. Luke's ship can maneuver (worth one letter 'step'):  You have implemented an additional set of options at the main menu that allows the player to move:

'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. The tie-fighter can move (worth two letter 'steps'):  Each tie fighter will randomly move it to one of the adjacent squares.  For practical purposes this means that the ship will move zero, or one rows up or down; zero, or one columns left or right.  The ship cannot move beyond the bounds of the array.  In the example shown in Table 2, the tie-fighter can move onto any of the squares numbered 1 - 9 (if they are inside the array) or it has a equal chance of remaining on the same square (one in nine probability).  It won't however move onto the vent (marked with a 'v').  To get credit for this feature your program does not have to check for ship-to-wall or ship-to-ship collisions: these situations should be handled by 'erasing' the destination square in the fashion described in the base version of the assignment.

1 2 3
4 H 6
7 8 9

Table 2: The tie-fighters can move onto any adjacent square within the trench.

  1. The game can be lost (worth one letter 'step'):  If Luke's ship has reached the last/20th column then he has over flown the target.  Because there isn't enough room in the trench to reverse course and since he doesn't have time to make another strafing run, the rebels have run out of time and the game has been lost (see Figure 4 bottom right).  In order for you to get credit for this feature you must have implemented feature #1 above first.  Also the cheat menu option 'm', to move Luke's ship, must work so that if the player selects this option and moves into column 20, the lose game condition will be detected by your program.  So the player can reach the lose game condition either by manually steering the ship or by using the cheat menu.   If feature #5 has also been implemented then moving onto rows 1 - 5 or rows 11 - 15 and the 20th column will result in Luke's ship colliding with a wall.   If feature #5 hasn't been implemented yet but feature #3 has then this will simply result in the lose game condition occurring because Luke has overflow the target.

Figure 4: The game is over (lost) when Luke reaches the far column.
  1. The game can be won (worth one letter 'step'):  If Luke's ship has reached row 9, column 19 (the location of the exhaust vent - see Figure 5, bottom right) then he has successfully destroyed the target.  (Fortunately for you your game does not require that you implement the ability to shoot lasers and launch torpedoes so flying over the target means that he has hit it).  Again in order for you to get credit for this feature you must have implemented feature #1 above first.  Also the cheat menu option 'm' to move Luke's ship must work so that if the player selects this option and moves onto the exhaust vent the game condition will be detected by your program.  So again  the player can reach the win game condition either by manually steering the ship or by using the cheat menu.

Figure 5: The game is won when Luke reaches the exhaust vent.
  1. Ships can collide with the walls (worth one letter 'step'):  If the tie fighter flies into the walls of the trench (rows 1 - 5 for the upper wall and rows 11 - 15 for the lower wall) it will be destroyed and leave some residue (see row 5, column 10 of Figure 6).  If Luke crashes into the wall his ship is destroyed and the game is lost.  (The residue will be the 'X' of his fighter). Again in order to get credit for this feature, features #1 & 2 must have been implemented first and the option to move Luke's ship into a wall of the trench must have been implemented in the cheat menu.  (You don't have to implement the option to move the tie-fighter because it tends to crash easily).

 
Figure 6A: Before the collision.   Figure 6B: A tie fighter has hit the wall the of the trench.
  1. Ships can collide with each other (worth one letter 'step'):  Since there is only one enemy fighter your program only has to check for collisions between the tie-fighter and Luke's ship. The collision will yield debris that looks like a wall collision (see Figure 7, row 8 column 9) and the game is lost.  In a fashion similar to previous features, features #1 & 2 must have been implemented first and the collision detection must be checked for when the user selects the 'm' option from the cheat menu.

Figure 6: Luke's ship has hit a tie-fighter!

 

Grades for non-functional assignments

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.

Hints for getting started for this assignment

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.

Other submission requirements

  1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step or more if your submission was implemented using bad style conventions (e.g., 'A' to 'A-' for employing poor naming conventions for identifiers, insufficient documentation, the use of global variables other than the flag for displaying debugging messages, using non-modular design or having an excessively large amount of redundant code in your program).

  2. Include a README file in your submission:  For this assignment your README file must indicate what grade level that you think your assignment should receive (e.g., 'A', 'B+' etc.) and the features that you have implemented.  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.

  3. Assignments (source code/dot-p file and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code/dot-p file and the README must be handed into the assignment drop box for the tutorial that you are registered in (located on the second floor of the Math Sciences building).  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.

  4. A demo is required for this assignment.  You will demonstrate the working features of your assignment to your TA, most likely it will occur in tutorials immediately after the assignment is due.  It is your responsibility to book a slot during the times allotted by your TA.  It isn't his or her job to chase you down and to set up a time.   If you do not demo your assignment then the highest possible grade that will get for this assignment is a 'D' regardless of how many features that are actually working.  This is because this assignment is fairly complex and I need to simplify the marking process to ensure that the assignments get graded and returned within a reasonable amount of time.

Sample Files

You can run a sample executable called "starwars" which can be found in Unix in the directory: /home/231/assignments/assignment6.  A portion of the source code, for initializing and displaying your array, will also be available in the assignment directory and is called "starwars.p".  You are allowed to use the source code in the starwars.p in your own assignment submission.

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.