CPSC 231: Assignment 6 (Worth 6%)
Due Tuesday March 22
New concepts to be applied in this assignment
-
Two dimensional arrays
-
Implementing a solution for a problem with a higher level of difficulty.
Introduction
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.
Although some have labeled his books as 'adult fairy tales' there are others
who made note of the deeper metaphorical references that are used throughout
his works. Perhaps because of the rich use of metaphors in his trilogy, 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 the
events of the Second World
War - although the latter two claims were vehemently denied by Tolkien.
It is a
testament to his literary genius that people today not only continue to
enjoy his work but continue to see deeper meanings. |
|
|
Assignment description
For this assignment you are to implement a
two dimensional text-based Lord of the Rings game. The game will
show an overhead view of the Middle Earth world:
|
Figure 1: A screenshot of 'Middle Earth: The
Adventure Game" |
To win the game the player,
who controls the hobbit Frodo (represented as the 'H' near the upper left hand
corner), needs to travel to forge of Mount Doom
(represented as the 'D' near the lower right hand corner). This is the only
place where the Ring of Power, which is borne by Frodo, can be destroyed.
The other inhabitants
of this world are controlled by the computer and will try to stop him in his quest
and they include the evil orc
(represented as the 'O') and the dreaded Nazgul (also known as the Ring Wraiths: represented
as the 'N').
The player loses the game if the either the orcs or the Nazgul end are in a
square that is adjacent to Frodo. The mountain ranges of Middle Earth are
represented by the 'M' character. None of the characters (player or
computer controlled) can enter a square that is occupied by a mountain. All data about the world will be stored in a
two-dimensional character array.
The game starts out by initializing the array to the default starting 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:
- Display the current state of the world onscreen.
- Display the main menu.
- Move Frodo based on the user's input (note: this occurs before the orc and the
Nazgul move).
- Move the orc and the Nazgul. In the full version of the game the
movement of these
creatures will be determined by your program. You
can write the code to move either the orc or the Nazgul first. To
the player the orc and the Nazgul will appear to move simultaneously because he
or she will not see the effect of the move until both of the
computer-controlled characters have moved (i.e., all the updated positions
when the game returns to step #1).
- Check the game status, determine if the player has won or lost the game and set the
appropriate flag.
- If the player has won or lost the game then an appropriate concluding
message will be displayed along with the final state of the world and the
program will end. If the player opts to quit the game early, then the
lose game message will appear and again the program will 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.
Grades for working assignments:
Basic assignment: C
- The 2D array representing the Middle Earth world will be displayed
at the beginning of each turn. Each array element must be bounded
on the top, bottom, left and right side with a line so that the display
of the world is framed by the grid shown in Figure 1.
|
- The world is initialized with the each object in the correct
starting location.
|
- There is a main menu of options displayed:
|
|
|
|
For this version of the assignment only
the quit game function is actually operational. 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 the C' or 'c' is entered (the cheat
menu, as described below, will be displayed onscreen).
|
- The cheat menu will display the list of allowable 'cheat'
operations:
|
|
- (d)ebugging messages toggle
|
|
- (n)azgul kills Frodo: lose game
|
|
- (o)rc kills Frodo: lose game
|
|
- (w)in game: Frodo reaches Mount Doom
|
|
|
|
As was the case with the main menu,
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. The only other option that needs to be functional for this version
is the quit cheat menu selection. Entering 'Q' or 'q' at the cheat
menu will bring the user back to the main menu.
|
Extra features:
- The player can move Frodo (worth 2 letter steps): The player
can move Frodo to any adjacent square that is not currently occupied.
The program must check if an invalid move is attempted: a) The destination is
already occupied, b) The destination is out of bounds, c) The destination not is
adjacent to the square currently occupied by Frodo. In these cases an
appropriate error message will be displayed and the program will continue
prompting the user for a destination square until a valid value is entered
|
Figure2 : The fate of all Middle Earth
depends upon your skill at guiding Frodo to Mount Doom |
As the player moves Frodo, he or she should keep in mind that hobbits are
not particularly good at combat (see Figure 3). Frodo should never get in combat range of one of the either the orc or the
Nazgul (i.e., the two are in squares that are adjacent). If this ever
happens, then Frodo is killed by the monster and the game is lost (see features #3
& 4).
|
Figure 3:
"I'm a gourmet not a fighter!" (A quote from a typical
hobbit at a Bilbo's big birthday bash). |
- The game can be won (worth 1 letter step): If the
player manages to move Frodo to Mount Doom (13,27) then the win game condition
has been met. The program will no longer loop to the next turn and
suitable congratulatory end game message will be displayed.
|
Figure 4: Frodo reaches Mount
Doom and saves Middle Earth! |
In order to get credit for this feature, the win game function of the cheat
menu must also be implemented (so that you and your TA can quickly determine
if your program is working). You will do this by re-setting the array
elements so that Frodo has reached row 13 and column 27, Mount Doom. Then
your program automatically check that the game has been won. The game
status flag will be set to the win game condition and game will end in the
fashion that's described above.
- The game is lost, Frodo has been killed by the orc (worth 1
letter step): If the orc and Frodo are ever adjacent to each other
at the end of a turn then the game is lost. The program will not
loop to the next turn and a suitable consolation message will be displayed to the
user.
|
Figure 5: Frodo will die if
he gets in range of the orc archer |
Again in order to get credit for this function the appropriate operation in
the cheat menu must also be implemented in a fashion similar to the win game
condition.
- The game is lost, Frodo has been killed by the Nazgul (worth 1
letter step): If the Nazgul and Frodo are ever adjacent to each
other at the end of a turn then the game is lost. The program will
not loop to the next turn and a slightly different consolation message than
the one above will be displayed to the user (i.e., your program must be
able to tell which lose game condition has occurred).
|
Figure 6: Frodo dies if the
Nazgul manages to close with him |
- The orc can move (worth 1 letter step): When the
movement phase for the orc occurs it will randomly move it to one of the adjacent squares.
For practical purposes this means that the orc will move zero, or one rows up
or down; zero, or one columns left or right. The orc cannot move beyond the
bounds of the array nor can the orc move onto a square that is already occupied.
|
Figure 7: The orc archer
travels from square to square looking for Frodo. |
- The Nazgul can move (worth 1 letter step): The Nazgul
moves in a different fashion from the orc because of it's semi-corporal
nature. During its movement phase it will disappear off it's current
square and it will randomly appear anywhere in one of the unoccupied squares of
the array. (This may include the square that it started from although
the possibility of this occurrence is very low).
|
Figure 8: The undead
Nazgul can travel from any square to any other unoccupied square. |
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 code for handling the user's selection
at the main menu:
|
- Get the menu selection from the user (you may actually combine this
into another module if you wish because it's such a simple operation).
|
- Identify and process the menu selection entered by the user (moving
Frodo, invoking the cheat menu or quitting the game).
|
- The first option will require the creation of several other modules:
|
|
- Get the destination (row, column) coordinates from the user.
|
|
- Determine if the row and column values are within the bounds of the
array.
|
|
- Determine if the destination square is occupied.
|
|
- Determine if the destination square is adjacent to the source square
(Frodo's current location).
|
|
- If the three conditions are not met then display an error message
and re-prompt the user for the destination square until all the
conditions have been met.
|
|
- If all three conditions are met then 'move' Frodo from the source
square to the destination square (JT's big hint: Frodo will occupy the
new array element while the previous array element now appears empty).
|
Other submission requirements
-
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).
-
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 or C) 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.
-
Assignments (source code and the README file) must be electronically
submitted via submit.
In addition a paper print out of the source code and 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.
-
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
"lotr" 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 "lotr.p". You are allowed to use the source code
in the lotr.p in your own assignment submission.
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 from the
movies are for
education fair use only and are not meant as a copy write challenge.