Homework #6
Due Friday, March 30th at 5pm
Note: bold text in the examples is input from the user.
Ringo should start in the octopus' garden just as before, but he must now make his way to a submarine refinery immediately south of the eels, collect/grab at least three drums of spent catalysts and resins (a big refinery like that should have about a dozen of them), and then deposit/throw them in the crab's place, carrying no more than one at a time. When Ringo deposits the third drum, the crab should become seething mad, and OPEC should get its answer.
Without a good mechanism for recording the locations of objects, this application will hopelessly complicate your simulator. You should therefore implement functions for the grab and throw commands, each of which should take an array of 100 enumerated Location types as a parameter (representing the locations of all the objects in the simulation), and update this array with whatever changes Ringo's actions effect. The functions should conform to the following prototypes:
void Grab ( Location locations[100] ) ; void Throw ( Location locations[100] ) ;and should be called from the switch/case statement in the main function of the program. Note that, since Ringo must still negotiate the octopus at the beginning of the simulation (by grabbing and throwing it, among other things), the code that controls this intercourse must be adapted to work within the function implementation described above. Hint: this can be done by adding Locations for Ringo's hand and the floor of the garden.
Example:
% a.out You're in the octopus' garden again. Your action: g You grab the octopus with your mighty European arms. Your action: t You throw the octopus onto the ground. It is momentarily dazed. Your action: e You swim east, out of the octopus' garden. This area is packed full of electric eels. Your action: s You swim south. There is a submarine refinery here, with plenty of liquid waste. Your action: g You grab a drum of liquid waste. Your action: n You swim north. This place is packed with eels. Your action: n You swim north. There is a crab here. Your action: t You throw a drum of liquid waste onto the ground. Your action: s You swim south. This area is packed full of electric eels. Your action: s You swim south. ... There is a crab here. Your action: t You throw a drum of liquid waste onto the ground. Three drums of liquid waste -- the crab becomes furious and OPEC pulls you out. Well done.
Use a two-dimensional five-by-five array of enumerated Location types to represent the extended seascape, and pass this array as an additional parameter to your Move function. The Move function should then find Ringo's current Location in this array and return the Location in the immediately adjacent array cell, in the appropriate direction. Test the program on the map below:
watery undersea Davy Jones spooky Micky Dolens
grave tomb locker sinkhole locker
sand bar prawn brine & crabs yellow
& grill shop spirits cottage submarine
coral pointy octopus eels mess of
reef rocks garden estates smelts
bunch of sunken stolen marine barnacle
shells pirate ship puppets refinery pile
manatee sea sea sea visitors
party horses cowboys monkeys center
Example:
% a.out You're in the octopus garden. Your action: g You grab the octopus with your mighty European arms. Your action: t You throw the octopus onto the ground. It is momentarily dazed. Your action: e You swim east, out of the octopus garden, into the eels estates. Your action: e You swim east, out of the eels estates, into the mess of smelts. Your action: s You swim south, out of the mess of smelts, into the barnacle pile. Your action: q You quit, bored of undersea life already.
void View ( Location map[5][5], string locnames[25] ) ;The array of strings should be initialized in the main function of your program to contain abbreviated names of the all the game locations, in the order of their Location type (cast as an integer), i.e. something like this:
locNames[(int)LOC_GRAVE] = "watery grave"; locNames[(int)LOC_TOMB] = "undersea tomb"; ...The View function must use the locnames array to print the map instead of a big printf statement, so that if anything changes the map, it will still print correctly when View is called. Note that the full names of the locations should still be printed whenever Ringo moves from one location to another, however, so you will need to maintain abbreviated and unabbreviated names for every location.
Example:
% a.out You're in the octopus garden. Your action: v watery grave undersea tomb DJ's locker sinkhole MD's locker sand bar/grill prawn shop brine/spirits crab yellow sub coral reef pointy rocks octopus eels smelts shells pirate ship puppets refinery barnacles manatee party sea horses sea cowboys sea monkeys visitor ctr Your action: q You quit, bored of undersea life already.