|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
Due Dec.07 (Fri) at the start of class
When playing the Grand Role-playing Underground Expedition (“gRUe”), an explorer wanders around different rooms, gathering treasures. An explorer can carry three treasures in their backpack; if they ever grab one treasure they will have to drop some other treasure. (Initially, an explorer's treasures are just three pieces of lint. The growth potential is huge!) A game session might look something like this:
Welcome to the world of gRUe. Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. Lying on the ground, there is: [1] some caffeinated mints (0.2 lbs). [2] a thumb drive (0.1 lbs) [3] a 72" golden iMac (45.0 lbs) [4] a whiteboard marker (0.2 lbs) >> What do you wish to do? help Please type one of the following commands: look inventory swap go help quit >> What do you wish to do? look Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. Lying on the ground, there is: [1] some caffeinated mints (0.2 lbs). [2] a thumb drive (0.1 lbs) [3] a 72" golden iMac (45.0 lbs) [4] a whiteboard marker (0.2 lbs) >> What do you wish to do? inventory You are carrying: [1] lint (0.0 lbs) [2] lint (0.0 lbs) [3] lint (0.0 lbs) >> What do you wish to do? swap You are carrying: [1] lint (0.0 lbs) [2] lint (0.0 lbs) [3] lint (0.0 lbs) What item do you wish to drop? 2 Lying on the ground, there is: [1] some caffeinated mints (0.2 lbs). [2] a thumb drive (0.1 lbs) [3] a 72" golden iMac (45.0 lbs) [4] a whiteboard marker (0.2 lbs) What item do you wish to grab? 1 You drop lint (0.0 lbs) -- a ball of fuzz. You grab some caffeinated mints (0.2 lbs) -- they smell like peppermint coffee. >> What do you wish to do? inventory You are carrying: [1] lint (0.0 lbs) [2] some caffeinated mints (0.2 lbs) [3] lint (0.0 lbs) >> What do you wish to do? look Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. Lying on the ground, there is: [1] lint (0.0 lbs) [2] a thumb drive (0.1 lbs) [3] a 72" golden iMac (45.0 lbs) [4] a whiteboard marker (0.2 lbs) >> What do you wish to do? go The adjacent rooms are: [1] Davis 2nd floor hallway [2] sidewalk between Davis and Stuart Which room would you like to go to? 2 sidewalk between Davis and Stuart: The sidewalk is covered in leaves. Lying on the ground, there is: [1] A scrap of paper. >> What do you wish to do? quip I'm sorry, I don't know how to quip. What do you wish to do? quit Bye!
Read all the instructions below before starting; re-read them periodically as you are writing your code.
For now: Do not deal withRoom s being connected to otherRoom s. That will be left for extra credit.
hint: Both Rooms and Explorers need to get a string that represents an array of Treasures. You won't repeat code1, of course; instead you will have a method to do this one sub-task. Which of your three different classes should best hold a method that takes in an array of Treasure, and returns a String description?
Note:This method supercedes the “grab” and “drop” methods from hw07'sclass Explorer . You will want to update thehandleOneCommand accordingly.
Note how between this method and the previous,
we are de-coupling input/output (I/O) from actually updating the
This is important if we ever (say) have an Explorer controlled by an AI —
they still need to
I should be able to run your program by typing java Explorer from the command line.
Handling the connection of rooms is slightly tricky. I recommand creating room-connections in two passes: First create many rooms, but don't (yet) initialize the field for its neighbors. Then, once all your rooms are mostly-initialized, you can add connections. Something along the lines of:
/** Create all the rooms in the game, connect them, and return * the particular room that a player will start in. * This method should be called exactly once, at the very start of the game. */ static Room setUpWorld() { Room rm1 = new Room ( … ); // rm1's "neighbors" field not yet initialized. Room rm2 = new Room ( … ); Room rm3 = new Room ( … ); Room rm4 = new Room ( … ); Room rm5 = new Room ( … ); Room[] neighborsOfRm1 = { rm4, rm2, rm5 }; r1.neighbors = neighborsOfRm1; ⋮ return r1; } |
This is a very open-ended assignment. Some possible extensions (in approximate order of complexity):
Add a weight limit, to how much an explorer can carry.
Right now a
One approach to implementing this would be having a
have a “parallel array” of (say, four) Strings
next to your array of four adjacent
Have
(One approach might be a single huge
1
After making this task its own separate helper method,
be sure to remove any now-redundant old copies of this code from
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Dec.12 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |