teaching machines

CS 145: Lab 11 – Objects with 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.

Checkpoint 1

Person A types. In Eclipse, create a lab11 package.

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 setNorth, setEast, setSouth, and setWest. Each accepts another Room as its sole parameter.
  • Getter methods getNorth, getEast, getSouth, and getWest. Each returns the Room in the given direction. If there is no room in the given direction, return null.

Create a class named TextAdventure with a main method. Declare and construct a network of at least four rooms. Connect them using your set* methods.

Checkpoint 2

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 n, e, s, and 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *