Project 3: Adventure Game, Part 2

Due: October 10


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.

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 (. for plains) and shows a mini map of the terrain in surrounding map squares:

> go east
Moving east...
You are at location 3,3 in terrain .
In this case there are mountains (M) to the east of the character, water (~) to the west and southwest, 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 northeast corner of the map:

The character should start out at (0, 0), which should be the top left 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 be able to read in a text file with the following format:

Here is an example of the contents of a map file:

10 12

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 and class 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.)


  10 Correctly submitted: main method is in Adventure class, no package
  10 Gets map file name from command line
  15 Reads map file
  15 Map class
  15 GameChar class
  10 go and inventory commands done by GameChar
  10 Prints coordinates and terrain of game character's location
  15 Prints 3x3 map grid after each move

-10 No source files submitted.
-10 More than one Scanner object for the standard input stream.