Introduction to Computer Science II by James Tam | Return to the course web page |
Background
It's hard to believe but the "Trek" franchise has been around for almost 40 years. Production of the first episode "The Cage" began in late 1964. It was given a budget by NBC of $640,000 and produced by Desilu Studios (which was since taken over by Paramount Studios). Since that historic date, Star Trek has become a part of television and motion picture history and includes an six separate TV series and ten motion pictures.
Your mission for this assignment
For this assignment you are to implement a simple Star Trek game. The Trek galaxy (i.e., the milky way) will be modeled with a ten-by-ten two-dimensional array of references. Each array element (called a "sector") will either be null (representing empty space) or contain a reference to a starship. Starships will be represented either by the 'H' character (which is the ship that is controlled by the human player) or a 'C' (for the three computer-controlled ships). When the game starts, the human player's starship will always start off in the same location, the "Terran sector", coordinates (0,0). The coordinates of the three computer-controlled ships will be randomly determined (see Figure 1 for an example of the initial starting configuration of the Galaxy).
Figure 1: Example starting positions.
Starships are equipped with a faster-than-light engines known as "warp drive". In terms of the game a ship can move into one of the adjacent sectors during the move phase (see Figure 2). Even with warp engines a ship still cannot leave the bounds of the galaxy (i.e., exceed the bounds of the array).
Figure 2: Warp drive can take a ship to any of the adjacent sectors Each starship equipped with a powerful (~1 Gigawatt) energy beam weapon called "phasers". Phasers can be used by the human player to attack the computer-controlled ships or vice-versa (see Figure 3 to see some phasers in action).
Figure 3: A starship firing its phasers Phasers have a limited range: only the ships in the adjacent sectors can be targeted. In the example shown in Figure 1 the human player's ship can't shoot at the computer controlled ships nor can the computer controlled ships target the player's ship. In Figure 4, the ship controlled by the human player at (1, 1) and the computer-controlled ship at (2, 1) are the only ships that can target each other with phasers. Note: Computer-controlled ships will only target the ship controlled by the human player and never each other. The ship controlled by the human player can never target itself.
Figure 4: Phasers have a limited range. For defence starships are equipped with a energy shield, or "shields" for short, that protects it from phaser hits (see Figure 5). A ship's shields can absorb a great deal of attacks before the energy in the shields dissipates, the shields "fall" or go "down". After that phaser hits will directly damage the ship's hull. The hull of a ship can only absorb a limited amount of damage before the ship is destroyed.
Figure 5: A direct phaser hit on the forward shields! Units for the phasers, shield and hull strength are measured in terms of "points". The number of points available for each of the ship's systems in this version of the Trek game will be as follows:
- Hull: May absorb up to 400 points of damage before the ship is destroyed.
- Shields: The number of energy points that the shields can absorb is equal to ten times the hull points of the ship (4000).
- Phasers: Each time that they are fired they will inflict between 80 and 800 points of damage on the enemy ship.
Phaser damage is deducted from the opposing ship first from the shields (until they reach a value of zero) and then from the hull. When the hull value of a ship reaches zero the ship is destroyed and is removed from the galaxy (that sector becomes empty).
Time passes in the game in terms of "turns". During each turn the following sub-turns will take place.
- The current state of the galaxy is displayed.
- The computer player moves its three ships (A+ version).
- The human player is given a chance to move his or her starship. The player is allowed to "pass" and not move the ship.
- The current state of the galaxy is displayed.
- The player's starship and any computer-controlled starships that are adjacent to the player's starship attack each other. In this version of the game attacks occur simultaneously (i.e., during a turn a computer-controlled starship and the player's starship could end up destroying each other at the same time). Again the player can pass on the attack phase although his or her ship will still be attacked by its computer controlled enemies.
- At the end of the program checks if the "game win" or "game lost" conditions apply. The player wins the game by destroying all of the computer's starships. The player loses the game when his or her ship is destroyed.
To help illustrate how combat in this works let's use the following example: we have played the game for period of time and we are faced with the following situation shown in Figure 6.
Figure 6 At the beginning of turn we have the following statistics for the 3 starships:
Human player
Ship's system Points Shields 925 Hull 400
Computer ship #1
Ship's system Points Shields 3236 Hull 400 Computer ship #2
Ship's system Points Shields 12 Hull 400 The human's starship targets the starship to its immediate right (Computer ship #2) and inflicts 792 points of damage. The damage is deducted first from that ship's shields leaving 780 points. The shield points for Computer ship #2 is now at zero (its shields are down). Since the remaining 780 points of phaser damage exceeds the 400 points for Computer ship #2 that ship has been destroyed. ("Got him sir!")
However because attacks occur simultaneously while the phaser beams for the human player's ship are hitting the computer player's ships, the computer controlled ships are also shooting back. Suppose that Computer ship #1 phasers generates a mere 107 points of damage while Computer ship #2 hits back at 880 points for a total of a whopping 987 points. Again the phaser damage is deducted from the shields until the shields fall. In this case the ship controlled by the human player absorb a total of 925 points of damage before failing leaving 62 points of damage that effects the hull leaving it with 338 points. So at the end of this round we are left with the following:
Human player
Ship's system Points Shields Down Hull 338 Computer ship #1
Ship's system Points Shields 3236 Hull 400 Computer ship #2
Ship's system Points Shields Down Hull Destroyed
Classes for this assignment
Your program must implement the classes shown below. Note: The list of attributes and mandatory behaviours are not meant to be as an exhaustive list (I had many more than the ones shown below and it is likely to be the same for your program). Also to shorten things I excluded the obvious methods that are needed such as accessor and mutator methods as well as the constructors.
class Trek: This is starting point for your program (contains the main method). Aside from declaring a few local instances of some of the other classes and calling some of their methods, the definition for this class should be very short.
Galaxy: Models all information associated with the Galaxy.
Attributes:
- grid: A 2D array of references to class StarShip. Indicates the position of all the ships as well which parts of space are empty.
- SIZE: A final attribute to indicate how large the galaxy is (10 for this game).
- MAX_OPPONENTS: A final attribute that indicates the maximum number of computer players in the game (3 for this assignment).
- You will also want to track which starship is controlled by the human player (a single instance of class StarShip) and as the ones that are controlled by the computer (a list of references to class StarShip).
Behaviours:
- Move ships from one sector to another (subject to their maximum range which is one sector in this version of the game but it may change in the next assignment so keep this in mind!)
- Displaying the galaxy.
- Checking the current state of the galaxy, determine if there are any actions that the program has to do or what actions are available to the players at that point in time. You will likely have to implement many methods to handle all these cases e.g., You will need a method to check if the player is able attack any other ships this turn - you can do this by checking if any of the adjacent squares contain a computer-controlled ship.
- StarShip: For this game there will be four instances of this class: 3 that are controlled by the computer and 1 that is controlled by the human player.
Attributes:
- appearance: a character is used to store the appearance of the ship: a 'H' for the human-player's ship and a 'C' for the computer's ships.
- hullValue: an integer that stores the current hull integrity (number of points) with a starting value of 400 each time that the game runs.
- shieldValue: an integer that stores the current shield strength (number of points). The starting value = (starting hull value) * 10 Note: the ratio of the shield points to the hull value may change in the next version of the game.
- current coordinates: the row/column coordinates of the ship in the galaxy.
- maxRange: an integer value that indicates the maximum number of sectors that a ship may move each turn. For this version of the game it is one but again this may change in the next version.
Behaviours:
- Determining the damage inflicted from the phasers when attacking another ship. (Remember it must a randomly derived integer value in the range of 80 - 800 inclusive of both end points).
- The ability to absorb the damage inflicted by other starships. When one ship is attacked by another ship, the second ship randomly generates a damage value for the phasers. The first ship must take this value and determine how much the shields and hull values get reduced. (Read the last section of this assignment description on features that may added on for Assignment 5 - otherwise you may have to totally rewrite this method when you get to the next assignment!)
- Determine the current state of the ship e.g., Is it true or false that the shields are down? Is the ship destroyed?
- Display the current state (shield strength and hull value) of the human player's ship after the attack phase (see Figure 7).
Figure 7: Status report of the player's ship after the attack phase is done.
- CommandProcessor: This class is responsible for getting input from the user and for displaying the menus of options that are available at a particular point in the game. Methods of this class take different actions based on the user's input by invoking the methods of the other classes.
Attributes:
- An instance of class Galaxy.
- The current menu option selected by the user.
Behaviours:
- Display the movement menu during the movement phase (see Figure 8).
- Display the attack menu during the attack phase (Figure 9).
- Note: With both menus if the user selects the 'q' option then the program will immediately end and display some sort of parting end game message (Figure 10). The pass option means that the player doesn't want to do anything during that turn (the ship doesn't move during the move phase or the person's ship doesn't attack during the attack phase - although any adjacent computer-controlled opponents will still attack the player's ship). Also note that as the program ends, a check must be performed to determine if the player won or lost the game. If so then the end message must indicate that either the person won or lost the game.
Figure 8: Movement menu
Figure 9: Attack menu
Figure 10: The end game message if the player quits the program at any time.
In addition your program must include my GameStatus class (or you write an equivalent class yourself).
class GameStatus
{
/* Required attributes */
public static boolean debugModeOn;
public static boolean cheatModeOn;
/* You may also want to add two optional additional static attributes */
public static boolean gameWon;
public static boolean gameLost;
}
Required attributes.
- debugModeOn: Indicates whether debugging statements show up as the program is run. The exact content of the debugging messages is up to you (see Figure 11 for some example output). Generally the messages that are displayed onscreen are used to help the programmer determine where bugs are and how to fix them e.g., when moving a starship your debugging messages may display the current row/column coordinates as well as the coordinates of where the ship is supposed to go. If this attribute is set to true then the debugging messages appear. If the attribute is set to false then no debugging message appear.
- cheatModeOn: Cheat mode will make the player controlled starship invulnerable. It cannot be damaged by the enemies' phasers. Setting this attribute to true turns on cheat mode while setting it to false turns off cheat mode.
Optional attributes.
- gameWon: This attribute is set to true when the win game condition (see above) is reached.
- gameLost: This attribute is set to true when the game is lost (see above).
- (It is possible for the player to quit the game without either the game win or game lost condition being met).
Of course if one these optional attributes is true then the other cannot be true. They can be used in different parts of your program to determine if it is time to end the game.
Basic submission (C-):
- Your program includes all of the required classes (although not all the methods may be fully implemented).
- Classes are instantiated and properly initialized e.g., For class galaxy the human player always starts off in the Terran sector while the starting positions for the computer controlled ships is randomly determined.
- The program displays the galaxy along with the bounding boxes around each sector and numbering for each row and column.
- The program displays the movement menu (Figure 8) and the attack menu (Figure 9).
- The human player's ship can warp to any adjacent square that is unoccupied.
- The person can put the program into debug mode from either the attack or movement menu (see Figure 11). The program should indicate to the user when it is in debug mode.
- The user can quit the game from either the movement or the attack menu.
Figure 11: Example output when debug mode is enabled
Extra features (completing all three can yield a grade of "A")
In order to receive a grade higher than a C-, you must first fulfill all the requirements of a C- assignment. Unless otherwise stated the extra features can be completed in whatever combination that you want.
Human player can attack any adjacent computer controlled ships (worth 2 grade steps).
Computer player can attack the human player's ship if it is adjacent (worth 2 grade steps).
The user can put the program into "cheat" mode from either the attack or movement menu (worth 2 grade steps). This menu option is a "secret" option that is hidden from the user of the program and when invoked it makes the human player's ship immune to the computer player's weapons. The human player can still damage the computer's ships as normal (this is why it's called cheat mode). A message should be displayed to the user to indicate whenever the game is in cheat mode (see Figure 12). Cheat mode can be toggled on and off: If the user selects option 'c' when cheat mode is off, cheat mode gets turned on. If the user selects option 'c' when cheat mode is on, cheat mode gets turned off. Of you get credit cheat mode only after you have implemented the code to allow the computer player ships to attack the human player's ship.
- Game can detect when the game has been won or lost (worth 1 grade step). Because winning or losing the game involves combat with other ships the first two extra features above must have been first implemented before the student can get credit for this feature.
Figure 12: Cheat mode enabled.
A+ level assignment
To be eligible for an A+ you need to have completed all the features for a C- assignment, all the extra features above plus your program will randomly move the computer controlled starships during the movement phase.
The student has invested considerable time and effort into the assignment, the program does not fulfill any of the above requirements but it does compile.
The student has invested considerable time and effort into the assignment, the program does not fulfill any of the above requirements and it does not compile.
2. Include a README file in your submission: For this assignment your README file must indicate what features have been completed as well as the estimated grade level. This will allow your marker to quickly determine what he or she must look for and speed up the marking process. Be specific about the features, don't just list the letter grade.
e.g., I completed the C- level requirements plus:
Total estimated grade = 1.7 + 4 steps = B.
As with previous assignments you must indicate if you use any external libraries (other than the tio or the ones produced by Sun).
3. Assignments (source code and the README file) must be electronically submitted via submit. In addition a paper print out of the source code and the README file must be handed into the assignment drop box for the lab 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.
1. The official Trek web site: www.startrek.com | |
2. To find out when your favourite episode will air on TV: www.spacecast.com | |
3. A nice description of the early beginnings of Star Trek: http://users.bigpond.net.au/adamdavini/History.html | |
4. A few sites in case you are really bored and have nothing to do: | |
http://www.ship3.fsnet.co.uk/handweapons_how.htm | |
http://www.rucus.ru.ac.za/~wolfman/Essays/Trek/trektalk.html |
These are some things to keep in mind as you design this program because if you make your program too specific for this assignment without considering possible future extensions then you may have to rewrite major sections of your Assignment 4 code.
Note: The use of the Star Trek © trademark was for educational purposes only and not meant as a copy write challenge.