Project 3: Adventure Game, Part 2

Due: October 10

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 command-line parameter. The format of the file is:

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 jar or zip file and turn the jar or zip file in on Canvas. Your files should not be inside a folder in the jar file, and you should not put in any files other than source files, class files, and an optional README.txt file. (The files and folders that are automatically added by the jar utility are okay.)

Points

10Correctly submitted: main method is in Adventure class, no package
10Gets map file name from command line
15Reads map file
10Map class
10GameChar class
10go and inventory commands done by GameChar
10Prints coordinates and terrain of game character's location
15Prints 3x3 map grid after each move
10Does not allow character to move out of bounds and prints error messages for attempts to move out of bounds.
100TOTAL
Deductions:
-20 No source files submitted.
-10 More than one Scanner object for the standard input stream.