Description
Specification
For this part of the adventure game project you will add a map with terrain to the game. As before, the main class
for your program should be called Adventure. Your program should accept the same commands and do the same
checking that were specified for Part 1. In addition, your program should have a Map class and a GameChar
class. The Map class includes a method to read a map from a text file. The GameChar class includes methods to
execute the go and inventory commands.
Your program should take a command-line parameter that tells the name of the map file to use. For example, to
use a map file named map1.txt, you can run your program with a command line like this:
java Adventure map1.txt
Each time the game character moves, your program should print a message showing the coordinates of the
square the character moved to and the terrain of the character’s location. After the line with the coordinates and
terrain of the game character’s square, the program should show the terrain of the map squares surrounding the
game character’s location. Surrounding map squares are shown in a 3 by 3 square of characters (letters, numbers,
or punctuation), with the center square showing the terrain in the square occupied by the game character. For
example, in the following excerpt from a game transcript, the game character moves east to location 3,3. The
message tells what kind of terrain the game character is in (M for mountains) and shows a mini map of the
terrain in surrounding map squares:
> go east
Moving east…
You are at location 3,4 in terrain M
..M
.MM
..M
In this case there are mountains (M) to the east, northeast, and southeast of the character, and plains (.)
everywhere else. In order to make the character’s position in the center of the square you should include
characters that represent out-of-bounds squares. Use a capital X to show that squares are off the map. The
following characters show the terrain display for a character in the northwest corner of the map:
XXX
X~~
X~~
The character should start out at (0, 0), which should be the top left (northwest) corner of the map. As for
Program 1, the first coordinate should be the north/south coordinate (row), which should increase when the game
character moves south. The second coordinate should be the east/west coordinate (column), which should
increase when the game character moves east.
The Map class
Your Map class should read in a text file that contains the map data. The name of the text file will be a commandline parameter. The format of the file is:
The first line contains two integers, separated by white space, that tell the number of rows (r) and columns
(c) in the map.
After the first line are r terrain lines, one for each row of the map. Each terrain line contains c characters.
The character at terrain line row in position col represents the terrain found at location row, col of the map.
Here is an example of the contents of a map file:
10 12
~~~~….MMMM
~~~….MMMM.
~~…MMMMMMM
~~~.MMMM*MMM
~~~..MMMMMMM
~~…fMMMMMM
~~.ffffMMMMM
~~..ffffff..
~~~~fffffff.
~~~~~~~fffff
Do not make any assumptions about the characters used to represent terrain. In other words, the maps I use to
grade your program will contain other characters besides M, ., f, and ~.
Your Map class should provide a method to get the terrain (represented by a char value). You will probably
want to also define a Loc class that contains row and column values.
The GameChar class
The go and inventory commands should be executed by an instance of the GameChar class. Also, the part of the
map visible to the character should be determined by a GameChar object so that if the character has special
abilities (a telescope) or limitations (no light in an indoor map) the map visibility can be adjusted accordingly.
(You don’t have to do anything with telescopes or light for this program.)
Bounds checking
Your program should use the size of the map when it checks to see if a move is valid. The size of the map is
specified in the map file.
Turn in
Put your source files into a zip file and turn the zip file in on Canvas. Your files should not be inside a folder in
the zip file, and you should not put in any files other than source files and an optional README.txt file.
Points
10 Correctly submitted: main method is in Adventure class, no package
10 Gets map file name from command line
15 Reads map file
10 Map class
10 GameChar class
10 go and inventory commands done by GameChar
10 Prints coordinates and terrain of game character’s location
15 Prints 3×3 map grid after each move
10 Does not allow character to move out of bounds and prints error messages for attempts to move out of
bounds.
100 TOTAL
Deductions:
-10 More than one Scanner object for the standard input stream.