CSCI 136
Fundamentals of Computer Science II
Spring 2017

Montana Tech
Computer Science & Software Engineering



ASSIGNMENT 3 - Dungeon 2

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 gain experience with exceptions.
  • You will read from and write to files.

Dungeon 2. This is the exciting sequel to your previous assignment. Dungeon 2 adds these new features: Getting started. Download the file dungeon2.zip. This contains the assets as well as some provided classes and some stubbed out classes. NOTE: You will use your Cell.java, CellPassage.java, CellDoor.java, Hero.java and Dungeon.java classes from the last assignment as a starting point. So copy these files into your new Dungeon 2 project directory. If there are problems with your previous submission, we will help you fix it up.

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 DungeonGame2 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:
Part 0: Dungeon creation using file input. We have provided a partially completed DungeonFactory class. This class provides static methods that handle 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 via a Scanner object.

Once complete, you can test it by running DungeonGame2 running it with a single command line argument:
% java DungeonGame2 d3.txt

Part 1: Changes to APIs. At this point, your program should compile. You should be able to run it on a dungeon without rocks by reading from standard input:
% java DungeonGame2 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 an array of image filenames. The first image in the array 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: You can test out your progress by running on a dungeon that includes rocks:
% java DungeonGame2 d4.txt
You should also add a status line at the top of the screen that shows the number of collected gems, keys, pickaxes, and elapsed time (rounded to two decimal places). 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 Time: 72.52
Part 3: High scores. Any good video game needs a high score screen. You need to complete the class HighScores that tracks the name and times of the fastest players. The HighScores class has a specified maximum size. Once the high score list is full, a new winner must have a time strictly less than one of the current entries in the list. The list is kept in order from fastest to slowest.

The HighScores class is given a filename that is used to load the previous best players. If the given filename does not exist, it initializes an empty high score list. The filename has a line for each entry, starting with the player's name followed by whitespace and then the player's elapsed time to clear the dungeon. Refer to the lecture on file I/O. This topic will be presented in class Friday 2/17.

We have provided a test main program. Assuming there is no scores.txt file to begin with, here is the output of two consecutive runs:
% java HighScores scores.txt 10

% more scores.txt
Keith   4.99
Bob     5.0
George  5.0
Hank    6.6
Abe     10.0
Carol   15.5
Edith   17.2
Dave    23.7
Lisa    23.7
Frank   23.9

% java HighScores scores.txt 10

% more scores.txt
Keith   4.99
Keith   4.99
Bob     5.0
George  5.0
Bob     5.0
George  5.0
Hank    6.6
Hank    6.6
Abe     10.0
Abe     10.0

Once you have implemented HighScores, you can test it out by giving two additional command line arguments to DungeonGame2 specifying the high score filename and the player's name.
% java DungeonGame2 d4.txt scores.txt Speedy
The game displays the high scores before the start of the game. Press spacebar to start the game. You can finish the game by either collecting all the gems or by hitting the 'q' key. Pressing the spacebar again will show you the high score list again. If you placed into the list, your new entry will be highlighted in red.




Grading
Grade ItemPoints PossiblePoints Earned
Program Compiles
1
Program Runs
1
javadoc Comments on All Classes and Methods
4
Part 1: API Changes
6
Part 2: Breakable Rocks
6
Part 3: Hero Status Line
6
Part 4: High Scores
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.java, CellPassage.java, CellRock.java, Dungeon.java, Hero.java, DungeonFactory.java and HighScores.java. 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 use javadoc comments. For extra-credit, please submit a single zip file containing all your programs/graphics/sounds/configuration files via the special extra-credit drop box.

Page last updated: January 04, 2018