![]() |
![]() |
|
Due Nov.1820 in class.
I have changed the deadline,
and streamlined the requirements and suggested-implementation a bit.
There will not be a wiki and/or reading set the explorer's status to…
and instead just have those methods return the value.
However, I will still give full credit
if you took that approach from an earlier version.
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!
The exploring will be done by a “top level” function
In general, the I/O (input and output) should all be localized just to
one or two top-level
For full credit, you should make sure user-input doesn't crash the program. (However this is a lower priority; you might work on that last. You will get most credit if you assume the user always enters a valid value (e.g. a valid backpack-index, etc.).)
pro tip: If you do want to make sure a valid number is entered, a good helper-function would bereadNumber(int max) which returns a number in 1..max, prompting the user repeatedly if necessary.
Read all the instructions below before starting; re-read them periodically as you are writing your code.
You are carryingfollowed by a string representing all the Treasures in the knapsack.
inv(or
inventory).
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?
We willmight eventually have ways for an explorer to interact with the world around them,
but that will have to wait since we don't yet have any classes to represent the world around them!
However, we will set up a framework suitable for future expansion.
(8pts) Write Explorer methods:
Dora is fed up with adventuring., and sets
Dora knows how to: look, swap, wait, eat, quit, help..
(5pts)
Write a function doesn't know how to cmd.
.
(Use one big, straightforward
You need only include 2 tests for this function3.
Those tests should be pretty easy, since if you pass in (say)
Note: this function does not read anything from the keyboard!
(See the next function, for that.)
(5pts)
Finally, putting it all together:
Write a method
Dora is a mite peckish..
At this point, you are off to an awesome start to having written an entire adventure game,
which we'll now finish upcan be expanded in the future!
Note: This method supercedes thegrabanddropmethods 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.
enjoyed a tasty snack.
is a mite peckish., otherwise it sets the status to
is bored.. (If you want to include the explorer's hunger-level in the resulting status, that's fine.)
swapcommand.
Right now a a door to the north
or a stairway leading down
)
and has to choose based on that.
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
Command pattern: You'll keep a list of "Command" objects — each Command object would include its own code and its own string, and then you would loop over that list until you found an object with the desired string. ↩
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |