teaching machines

CS 145 Lab 11 – Objects

December 1, 2019 by . Filed under cs1, cs145, fall 2019, labs.

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. Create a labs.lab11 package.

Room

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:

TextAdventure

Create a class named TextAdventure with a main method. Declare and construct at least four Room instances. Connect them into a map using your set* methods.

Checkpoint 2

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 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.