Lecture notes for Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 5

New Concepts to be applied for the assignment

Introduction

Prior to writing his famous trilogy: The Lord of the Rings, Professor John Robert Reuel Tolkien had already published "The Hobbit"1 a tale of the adventure of Bilbo Baggins and the Company of thirteen dwarves.  (JT's comment: This is an exert from the second edition of the book that could describe the plot far better than I ever could): 

"The Hobbit is a tale of high adventure, undertaken by a company of dwarves, in search of dragon-guarded gold.  A reluctant partner in this perilous quest is Bilbo Baggins, a comfort-loving, unambitious hobbit, who surprises even himself by his resourcefulness and his skill as a burglar.

Encounters with trolls, goblins, dwarves, elves and giant spiders, conversations with the dragon, Smaug the Magnificent, and a rather unwilling presence at the Battle of the Five Armies are some of the adventures that befall Bilbo.  But there are lighter moments as well: good fellowship, welcome meals and song."

For this assignment you are to write a text based game with an overhead view of the dwarven kingdom: Erebor (see Figure 2).  This game re-creates the portion of Bilbo's quest just after the secret entrance tunnel to Erebor has been discovered and a 'volunteer' is needed to go in. The full version of the game will allow Bilbo to sneak into the Erebor in order to retrieve as much of the treasure as possible. The treasure is guarded by the dragon "Smaug the Golden". Although Smaug himself doesn't directly appear in the game the effects of his dragon fire do. At the start of the game Bilbo starts off at the entrance to the dwarven hall (0,E).  Smaug will be asleep so Bilbo can freely move about (the game is in "mode 1").    Once Bilbo is in the main hall Smaug will awaken and begin bombarding the hall with fireballs (the game now enters "mode 2").  Bilbo, like all Hobbits, is a stout fellow but even he cannot withstand dragon fire for long so it will be a tradeoff between collecting as much treasure as possible and getting out of Erebor alive. Once Bilbo has reached the entrance tunnel, Smaug knows that the would be thief has almost escaped so he will stop breathing fire into the main hall but will instead focus on the tunnel.  By the time that Bilbo starts moving back up the tunnel's exit, Smaug will have positioned himself at the entrance to the tunnel and start breathing fire into it (the game now enters "mode 3").  At this point it's a race against time for Bilbo (actually a race against the flames) as he tries to reach the entrance before he gets caught by the fire.  If Bilbo's hit points reaches zero then he has been slain, the player has lost and the game ends.  If however Bilbo returns to the entrance/exit then the game ends and the player's success is determined by how much treasure has been gathered.

The world will consist of a 2D list but do unlike the previous assignment do not make each list element a string of length 1. All but one of the list elements will consist of an object of type MEObject (actually a reference to that object). MEObject will have one attribute called 'appearance' which in turn is a string of length one. Different characters will be used to represent different types of Middle Earth objects: <space> = empty locations, '*' = dragon fire, 't' = treasure, '#' = wall.

 
Figure 1: The reluctant participant in the quest, Bilbo Baggins.

 


Figure 2: Erebor, the game world

Features to implement

  1. Displays an introduction at the beginning of the game just after it starts. The introduction should explain the rules.
 
  1. Displays a conclusion when the game ends. In the full version of the game it should display the game state: lost (Bilbo slain), exited (Bilbo reaches exit) and how much treasure (if any) was collected by the player.
 
  1. The game world 'Erebor' consists of a list of (references to) objects. The list is initialized with the start positions of all the entities in Erebor. (Your program must use the same starting positions as mine). The positions are determined using option 1 or option 2 (second option is worth more credit). Each list element is an object of type MEObject (except for Bilbo which is an object of type Hobbit).
 
 
  1. Option 1: Start positions are hard coded (fixed) by calling function 'hardCoded' (the code for this function can be found in the assignment directory).
 
 
  1. Option 2: Student writes the code to read the start positions from the file called 'input.txt' (the data file can be found in the assignment directory).
 
  1. The program should display the game world using a numbered grid so that columns and rows can be clearly identified.
 
  1. As Erebor is displayed, information about Bilbo's current hit point level and gold collected is also shown (see top Figure 2).
 
  1. Displays the main (move) menu to the player. The 4 cardinal directions (N, S, E, W) and inter-cardinal directions (NW, NE, SW, SE) are mapped to positions on the computer keypad (1 = SW, 2 = S, 3 = SE, 4 = W, 5 = No move, 6 = E, 7 = NW, 8 = N, 9 = NE).
 
  1. If the player selects a hidden option '0' at the main menu then the cheat menu will be displayed. Cheat options: (d)ebug mode toggle (i)nvulnerability mode (q)uit cheat menu and return to main menu. Program can get user selection and quit the cheat menu.
 
  1. Player can quit the game by entering a negative value at the main menu.
 
  1. Class Hobbit has been defined with the following default attributes: hitPoints = 20, gold = 0, appearance = 'H'Bilbo's hit points will go down as he is comes into contact with dragon fire. If Bilbo is slain then his appearance will become an exclamation '!'.
 
  1. Debug mode implemented: To get credit for this feature the player can toggle debugging messages on/off at the cheat menu and debugging messages will be displayed during the 'on' state. In order to get credit for features labeled "Debug must show feature working" debug mode must show enough information so that the marker can quickly determine if the feature has been implemented correctly. You can check with your marker for the specifics on this but generally you are should show the value of different variables to demonstrate that the feature works e.g., when Bilbo is invulnerable show him getting hit with dragon fire but a message is displayed indicating that he won't take damage, when invulnerability is turned off show him taking damage (hit points before, damage inflicted, hit points afterwards).
 
  1. Invulnerability mode implemented. It's toggled on/off at the cheat menu. When turned on, Bilbo will not take damage. Debug must show feature working.
 
  1. Bilbo can move onto any location (except for walls). You will progressively receive more credit as you implement more of the sub-features listed below (a) - (c). Debug must show feature working.
 
 
  1. Bilbo can move from one square to another (except into walls).
 
 
  1. Bilbo will take 2- 8 points of damage if he's moved onto a square that contains dragon fire '*'
 
 
  1. Bilbo will pick up 1 - 6 pieces of gold from squares that contain treasure 't'. The treasure is gone after Bilbo has picked it up and won't appear after he leaves the square.
 
  1. Mode 2 implemented: as long as Bilbo is in the main hall Smaug will breath fire into the hall. Each turn some randomly determined locations will contain dragon fire. Locations that previously contained fire can either contain fire again or the fire may die out if Smaug doesn't breath into the same location. Potentially any empty square (or the one containing Bilbo) in the main hall can be hit with the fire. You will progressively receive more credit as you implement more of the sub-features listed below (a) - (d). Debug must show feature working.
 
 
  1. Each square has a 10% chance of getting blasted with fire. Squares that were hit previously (but not hit again this turn) will revert back to their old appearance.
 
 
  1. Dragon fire only appears in  empty squares (or the one containing Bilbo).
 
 
  1. If the fire appears in the same square as Bilbo then he sustains 2 - 8 points of damage.
 
 
  1. Bilbo's appearance changes to a star while he has been hit with dragon fire. If he isn't burnt again the next turn then his appearance reverts to it's appropriate form 'H' (alive) or '!' (slain).
 
  1. Mode 3 implemented: When the player re-enters the tunnel (from the main hall: location row = 14, column = 15) then the dragon fires in the main hall will die out (the squares will be cleared) and a message will appear indicating that Smaug is now moving towards the tunnel.  When the player moves off this square (up or down - although the latter wouldn't be a good idea for the player because Bilbo is now trapped by the flame...in this latter case the program stays in mode 3 and doesn't revert back to mode 2) fire will appear at row 13, column 14 (entrance to the main hall. The distance that the fire travels from this spot. will be determined as follows: 50% of the time Smaug's fire will travel zero squares, 25% of the time it will move up one square while the remainder of the time it will move up two squares.  The fire is progressive, once it appears in the tunnel it won't die out and will travel 0 - 2 squares each turn. Debug must show feature working.
 
  1. Program can detect the lose gain condition (Bilbo's hit points reaches zero or less and he is slain). At this point Bilbo's appearance should change to '!', the world should be displayed one last time and the game should end with an appropriate status message displayed. The player is not eligible for a high score. Debug must show feature working.
 
  1. Program can determine when the exit has been reached by Bilbo (he re-enters row 1). At this point the game should end and a status message should appear that indicates that Bilbo has escaped as well as the amount of treasure that he managed to get (this is the player's 'score').
 
  1. The program will save the highest score to a file called 'score.txt'. Initially the score starts a zero. Each time that the program ends it will compare the current score with the saved value and if the current score is higher it will save this one to the file.
 
  1. Extra bonus feature: instead of displaying the simulation in text QuickDraw is used. The interface itself can still be console based (i.e., select a menu option via console input) just the output can be graphical. Your graphics don't have to be fancy (e.g., you can use different primitives, color and/or text to distinguish the runners) but the graphical version must clearly represent the same information as the text-based equivalent (e.g., don't use rectangles of the same size and appearance for Bilbo, the treasure, the walls and the dragon fire). You won't get a lot of extra marks for implementing this feature (because graphics isn't a key feature of this program). But I did include this feature in case you wanted to spice up your program and/or you wanted to increase the probability that your assignment received a higher grade.
 

Components of a turn

Submitting your work:

  1. Similar to the previous assignment you must create a README file that lists all the features that were implemented. Assignments (source code/'dot-py' files containing your Python program and your file README) must be electronically submitted according to [the assignment submission requirements].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

Exert from the 'Hobbit' where Bilbo sneaks into the lair of Smaug [YouTube]

1The Lord of the Rings trademark is owned by Tolkien Enterprises.  The license to the movie is owned by Warner Brothers..   References to either the original trademark or the inclusion of images from the movie are for education fair use only and are not meant as a copy write challenge.