CS 148 Lab 11 – Objects
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. 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:
- A constructor that accepts as a parameter a description of the room. It sets up the room to initially have no connections to other rooms.
Give it the following behaviors:
- Setter methods
setWest. Each accepts another
Roomas its sole parameter.
- Getter methods
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 at least four
Room instances. Connect them into a map using your
Person B types. Tweak
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.
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.