Introduction to Computer Science II by James Tam | Return to the course web page |
Due Friday November 26th.
Professor John Robert Reuel Tolkien was a faculty member at the prestigious Oxford university. He begin work on "The Lord of the Rings" trilogy shortly before "The Hobbit" was published in 1937. Perhaps because of the rich use of metaphors in his work, many continue to draw parallels between his books and actual events in history: the Wain riders are said to be patterned after the Mongol invaders of Europe, the "War of the ring" was supposedly influenced by Second World War - all of which was vehemently denied by Tolkien. Perhaps it is a testimate to his literary genius that people today not only continue to enjoy his work but continue to see deeper meanings. |
D+ grade: The default values for Middle Earth have been properly initialized: the mountains are instances of class MEObject that are in the correct starting positions. The program can display the current state of the world onscreen. The student has implemented a CommandProcessor class that will display a menu of "Game options" for each turn. The menu will only have limited functionality for this grade level: 1) To quit the game 2) To not quit the game and continue onto the next turn (i.e., display Middle Earth again) 3) To invoke the cheat menu (which will be a hidden menu option "X"). For this grade level your cheat menu doesn't have to do anything so it's sufficient that the 'X' option just displays an empty menu.
Game options:
(Q)uit gameCheat menu:
(Q)uit cheat menuFor C- and higher grade levels, you will implement a turn based game and each turn will be divided into two parts: 1) The sub-turn for the computer-controlled creatures (Gollum may move or escape, if he is in custody, and the Nazgul may move or attack) 2) The human player's turn (when the above game option menu will be displayed).
Implementation requirements for the higher grade levels: You need to implement six classes: Hobbit, Gollum, Nazgul, MiddleEarth, CommandProcessor and World.
Each of the first three classes (Hobbit, Gollum and Nazgul) must extend class MECreature (see the directory /home/233/assignments/assignment5 for the source code but below is a brief description of the high lights):
A Middle Earth creature has an integer attribute called "hit points" which determines the amount of damage that a creature can absorb in combat before the creature dies. The default hit point value is six. If one creature is adjacent to another creature combat may occur. The damage that the attacking creature inflicts on the other creature is determined by the "attack" method (described below). The damage will be deducted from the hit point attribute of the creature which has been attacked. When a creature's hit points reaches zero (or less) that creature dies and it is removed from the world (the square that contains it will appear empty the next time that world is displayed).
Class MECreature is an abstract class and instances cannot be directly instantiated because it includes an abstract attack method. This class only defines the signature of this method; the body of the method will be implemented differently by the three child classes of this class.
Finally a MECreature will have the prerequisite constructor, accessor and mutator methods.
Class MECreature extends class MEObject so that your classes will indirectly inherit from the latter class. Again you can view and copy the source code for this class from the appropriate assignment directory but a high light of the key points include:
Each Middle Earth object will store information about its appearance.
An individual Middle Earth object will constantly track it's location in the world in terms of the object's (row, column coordinates).
The object has the ability to return it's state in the form of a String (i.e., it overrides the toString () method).
- As was the case of the MECreature, a MEObject will have the prerequisite constructor, accessor and mutator methods.
1) The Hobbit class:
An instance of class Hobbit, called "Frodo", will be controlled by the player of the game. The hobbit will represented in the game with the 'H' character. Frodo will always start the game at position (1,1), "The Shire", and can move up to one square each turn. The player wins the game when Gollum has been captured (see the description for the Gollum class) and they travel to Mount Doom, position (12,17) marked with a "D" on the map. The player loses the game if Frodo's hit points ever reaches zero or if he attacks and kills Gollum. Although they may not look soft and weak , hobbits are surprisingly sturdy creatures that can absorb a fair amount of damage. Consequently they each have twenty hit points. However, hobbits have a poor attack capability, "I'm a gourmet not a fighter!" The amount of damage that they inflict will be an integer value from 1 - 6 (inclusive). This randomly generated value will be calculated when you implement the "attack" method which instances of class Hobbit must implement. Because of their lack of combat skill, each hobbit will have another attribute which reflects the percentage chance that it can escape combat. When Frodo is in a square that is adjacent to the Nazgul, he has a 30% chance of remaining undetected and avoiding a fight. (Meaning that 30% of the time Frodo won't remain hidden from the Nazgul but 70% of the time Frodo will still be found and attacked by the Nazgul). The hobbit's ability the avoid combat is not automatic and must be consciously invoked. This reflects the fact that the hobbit is not naturally invisible but must try to actively hide from it's enemies in order to go unnoticed. In terms of the game, when you implement the hobbit class you will need to add three menu options: 1) The option for Frodo to move 2) The option for Frodo to attack 3) The option for Frodo to hide. The latter two options will only appear when Frodo is adjacent to another MECreature. Game options:
(A)ttack
(H)ide
(M)ove
(Q)uit gameMarks for implementing the Hobbit class (max of two grade steps):
- +1 letter step for defining the attributes of a hobbit and overriding the attack method.
- +1 letter step if your game can detect that when Frodo dies, the lose game condition has occurred. In order to get credit for this feature you need to be able to quickly demonstrate that your program is working to your marker. Consequently you must implement an option in the cheat menu:
Cheat menu:
(D)eath of Frodo, game lost
(Q)uit cheat menuYour program will then immediately indicate to the player has gotten Frodo killed and that game cannot be won without him. Hint: The easiest way to do this is set Frodo's hit points to zero and the game status flag to indicate that the game has been lost (you will also need to get your program to detect this condition).
Note: because most of the features of the other two classes only become evident when instances of them are interacting with Frodo, typically you must first implement the code for the Hobbit class before you can get any credit for the other two classes.
3) The Nazgul class:
Except for the Dark Lord Sauron, the Nazgul are the deadliest opponents that Frodo will encounter in Middle Earth. Each Nazgul, was once a human that was given one of the lesser rings of power by Sauron and was eventually corrupted by the power of the rings. For this version of the game there will be only one Nazgul (fortunately for Frodo!) Each Nazgul has the ability to both mete out a devastating amount of damage as well as stamina to absorb many attacks. They start out with 113 hit points and each attack inflicts 1 - 10 points of damage (inclusive). The Nazgul will start out at position (11,16) and then randomly "teleport" into the one of the grey squares marked on the map. The Nazgul is represented with the "N" character in this game. Marks for class Nazgul (max of two grade steps):
- +1 step for properly defining the Nazgul class, setting the hit points and appearance as well as the correct implementation of the attack method. The Nazgul will automatically attack Frodo whenever the two are in adjacent squares unless Frodo manages a successful evasion attempt. Gollum will be attacked by the Nazgul.
- +1 step for implementing the code to allow the Nazgul to move. As stated earlier the Nazgul will randomly move into one of the squares from (11,16) to (14,19) except for the square that contains Mount Doom (12,17) or when a square is occupied. Unlike the case with Gollum, the randomly generated set of destination coordinates can be identical to the current ones. However, the Nazgul will not move if it is already in combat with Frodo. It will continue attacking him until either Frodo moves to an adjacent square or if Frodo makes a successful hide attempt.
Pre-created code that you have to use for all grade levels (which can be found in the assignment directory):
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.
The Lord of the Rings trademark is owned by Tolkien Enterprises. The license to the Lord of the Rings movie trilogy is owned by New Line Entertainment. References to either the original trademark or the inclusion of images are for education fair use only and not meant as a copy write challenge.