NEWS FLASH!!! THIS ASSIGNMENT IS OPTIONAL!! SHOULD YOU CHOOSE TO DO IT, IT WILL REPLACE YOUR LOWEST SCORE LAB
In this assignment, you will be extending the game you made for the last assignment.
You will extend an existing class hierarchy to add additional functionality.
You will refactor code to make the program simpler.
Dungeon 2.
This is the exciting sequel to your previous assignment. Dungeon 2 adds these new features:
Higher resolution graphics.
Items that are reuseable, in particular pickaxes.
Rocks that block the hero, but can be broken through using a pickaxe.
Hero status display showing number of items collected.
Game can actually be won by collecting all the gems.
Getting started.
Download the file dungeon2.zip.
This contains the assets as well as some provided classes and some stubbed out classes.
NOTE: You may use your own Cell.py, CellPassage.py, CellDoor.py, Hero.py and Dungeon.py classes from the last assignment as a starting point, or you may use the ones provided.
Whichever you choose, copy these files into your new Dungeon 2 project directory.
Dungeon definition.
The dungeon definition is similar to the previous assignment, but there are now breakable rocks in the dungeon denoted by an 'R'.
Also the second line now contains the number of gems, keys, and pickaxes to randomly place in the dungeon.
As such, the files from your last dungeon assignment won't work with the new DungeonGame main program.
Here is what d4.txt looks like:
13 10
10 4 2
1 1
W W W W W W W W W W W W W
W - W - - - - - - D - - W
W - R - W W W - W W - - W
W - W - S - S - W W - - W
W - R - W W W - W W W O W
W - W - W W W D W W - - W
W - W - W - - - - D - - W
W W W - W - W - - W - - W
W - - - W - W - - W - - W
W W W W W W W W W W W W W
Updated Config. The provided Config class has been changed in the following ways:
Uses a new set of image assets.
Increases the cell size to 64 pixels.
Adds a quit action so players can hit 'q' to end the game.
Adds the method rockImages to provide the progression of images for the rock.
Adds the method itemWasConsumed to test whether using an item has caused it to be consumed (e.g. a key opening a door, a pickaxe that has broken).
Adds the method mapItemToConsumedSound to provide sounds effect when an item is consumed.
Part 0: Dungeon creation using file input. We have provided a partially completed DungeonFactory class.
This class provides a method that handles all the work associated with instantiating a Dungeon object.
The code that used to live in the main game program to read in a file should now be all tucked away in this factory class.
You are to implement the createFromFile method.
This method should construct a Dungeon using file input.
HINT: You may re-use much of the code provided in DungeonGame.py from the last lab assignment.
Once complete, you can test it by running DungeonGame running it with a single command line argument:
% python DungeonGame.py d3.txt
Part 1: Changes to APIs.
We need a new method that allows us to ask any object of type Cell (or its subclasses) if it currently contains a given item.
Add the method containsItem to the Cell API.
This method takes an Item as input and returns true if the cell contains that type of item, false otherwise.
Hint: You will have to implement the method in one class as well as override it in another class.
Using the new containsItem method, implement a new method in Dungeon named getCount.
This method takes an Item as input and returns the integer count of the number of cells in the dungeon that have that item.
This is used by DungeonGame to determine when a player has cleared all the gems from the dungeon.
It should also work for counting the number of other objects (e.g. keys or pickaxes) in the dungeon.
In the Dungeon class, the execute method must return True if the game is still on, or False if the user has chosen to quite the game (by pressing the 'q' key).
The Dungeon API needs two new methods: getWidth and getHeight.
These methods return integer values specifying how many cells wide and hight the dungeon is.
This is required by DungeonGame in order to setup its drawing window.
At this point, your program should compile.
You should be able to run it on a dungeon without rocks by reading from standard input:
% python DungeonGame.py d3.txt
If you implemented containsItem and getCount correctly, you should be able to win the game by collecting all the gems.
If last time you implemented collectItem in Hero in a general manner, you should notice that collecting a pickaxe results in a new sound effect.
If not, you'll need to add logic to the Hero class in the next part to handle pickaxes.
Part 2: Breakable rocks and hero status.
To support the new breakable rock feature, we have added a new PICKAXE value to the Item enumeration.
We have also added rockImages to Config that returns a list of image filenames.
The first image in the list is the starting point for a rock.
Each time a rock is pickaxed, it goes to the next image and the use item sound effect is played.
Every time the pickaxe is used, there is a 5% chance that the axe breaks.
If the axe breaks, the item consumed sound effect is played.
Once it reaches the final image, the passage way is clear and the hero is thereafter allowed to walk through that cell.
We have given you only a basic stub for CellRock.
A variety of changes need to happen to realize your rock-breaking dream:
Decide what class CellRock should extend.
Add attribute(s) to CellRock to allow objects of this type to track the set of images as well as the current state of the rock.
Override the methods attemptToMove and draw in CellRock to make CellRock behave as described.
Modify set in Dungeon to allow creation of CellRock objects.
Modify collectItem in Hero to keep track of the number of pickaxes the hero has (this might not be necessary if you implement this last time in a nice general way).
Modify attemptToUse in Hero to deal with objects like the pickaxe that may or may not be consumed during use.
To help with this use the itemWasConsumed method in Config.
You will also need to use the mapItemToConsumeSound which plays a sound when an item is used up (e.g. when a key opens a door, or when the pickaxe breaks).
You should play the use item sound effect first, and then play the consume sound effect if an item was actually used up.
You can test out your progress by running on a dungeon that includes rocks:
% python DungeonGame.py d4.txt
You should also add a status line at the top of the screen that shows the number of collected gems, keys, and pickaxes. The exact position, color, font size, and justification is up to you, just be sure that it is readable and doesn't obstruct a player's view. You can assume the top row of the dungeon will be a wall as in d4.txt.
For example: Gems: 5 Keys: 2 Pickaxes: 0 Grading
Grade Item
Points Possible
Points Earned
Header: Name and Description on ALL FILES
3
Program Compiles and Runs
3
Part 0: DungeonFactory
6
Part 1: API Changes
6
Part 2: Breakable Rocks
6
Hero Status Line, Allows Quit, Ends Game on Win
6
Total
30
Where did you get the graphics?
For this assignment, Keith started with this 128 x 128 tile set from the Slash'EM game.
Extra credit.
Make the game better.
You might want to use some of the extra images provided in dungeon2-extra-assets.zip.
Or you could also cut them out of the extremely large (20MB) image linked above.
Please see the note below on how to submit your extra-credit creation.
Be sure to submit your regular submission first and ensure it works per the assignment specifications.
Submission.
Submit all the classes you changed: Cell.py, CellPassage.py, CellRock.py, Dungeon.py, Hero.py, and DungeonFactory.py.
Be sure each submitted source file has the required header with your name and a description of the program and all your classes and methods are commented.
For extra-credit, please submit a single zip file containing all your programs/graphics/sounds/configuration files via the special extra-credit drop box.