Welcome to lab 11!
If you have checkpoints from the last lab to show your instructor or TA, do so immediately. No credit will be given if you have not already completed the work, nor will credit be given after the first 10 minutes of this lab.
In this lab you will create a bare-bones text-based adventure game, in which a player moves through a network of rooms, achieving some objective—like collecting items or solving puzzles.
Person A types. In Eclipse, create a
Create a class named
Room that knows at least five things about itself: its textual description and which
Rooms are to its north, east, south, and west. Give it the following:
Give it the following behaviors:
setWest. Each accepts another
Roomas its sole parameter.
getWest. Each returns the
Roomin the given direction. If there is no room in the given direction, return
Create a class named
TextAdventure with a
main method. Declare and construct a network of at least four rooms. Connect them using your
Person B types. Extend
TextAdventure.main by first adding a variable to track the player’s current room. Start the player in one of the rooms that person A has already constructed—do not construct a new room.
Then continuously prompt the user for text command and respond accordingly. Respond to commands
w by attempting to move the player to the room in the given direction. For example, if
n is typed, move to the room north of the current room.
When a room is entered, display its description.
For example, consider this interaction with just two rooms:
You look around. The room is completely black. Suddenly, a flame lights up. It ignites the end of cigarette, which is perched in the mouth of a clown. He is not smiling. > n Three clowns sit around a table playing cards. They nod as you enter and return to their game. > e There is no room to the east. > s You look around. The room is completely black. Suddenly, a flame lights up. It ignites the end of cigarette, which is perched in the mouth of a clown. He is not smiling.
Support at least one other meaningful command of your choosing that allows the player to interact with a room. For example, maybe a room contains items that can be taken and added to the player’s inventory. Maybe the doors are locked and need to be unlocked in some way. You decide. Add methods to
Room as needed.
Consider adding a win condition appropriate for your interaction.
Invite another team over to playtest your text adventure.