Java Reference
In-Depth Information
The project shows five classes. They are Parser , CommandWords , Command , Room , and
Game . An investigation of the source code shows, fortunately, that these classes are quite
well documented, and we can get an initial overview of what they do by just reading the class
comment at the top of each class. (This fact also serves to illustrate that bad design involves
something deeper than simply the way a class looks or how good its documentation is.) Our
understanding of the game will be assisted by having a look at the source code to see what
methods each class has and what some of the methods appear to do. Here, we summarize the
purpose of each class:
CommandWords The CommandWords class defines all valid commands in the game. It does
this by holding an array of String objects representing the command words.
Parser The parser reads lines of input from the terminal and tries to interpret them as
commands. It creates objects of class Command that represent the command that was
Command A Command object represents a command that was entered by the user. It has
methods that make it easy for us to check whether this was a valid command and to get the
first and second words of the command as separate strings.
Room A Room object represents a location in a game. Rooms can have exits that lead to other
Game The Game class is the main class of the game. It sets up the game and then enters a
loop to read and execute commands. It also contains the code that implements each user
Exercise 6.3 Design your own game scenario. Do this away from the computer. Do not
think about implementation, classes, or even programming in general. Just think about invent-
ing an interesting game. This could be done with a group of people.
The game can be anything that has as its base structure a player moving through different
locations. Here are some examples:
You are a white blood cell traveling through the body in search of viruses to attack. . .
You are lost in a shopping mall and must find the exit. . .
You are a mole in its burrow and you cannot remember where you stored your food
reserves before winter. . .
You are an adventurer who searches through a dungeon full of monsters and other
characters. . .
You are from the bomb squad and must find and defuse a bomb before it goes off. . .
Make sure that your game has a goal (so that it has an end and the player can “win”). Try to
think of many things to make the game interesting (trap doors, magic items, characters that
help you only if you feed them, time limits. . . whatever you like). Let your imagination run wild.
At this stage, do not worry about how to implement these things.
Search WWH ::

Custom Search