Homework #5
Due Friday, March 9th at 5pm
Note: bold text in the examples is input from the user.
| n | - | swim north |
| s | - | swim south |
| e | - | swim east |
| w | - | swim west |
| y | - | yell |
| h | - | hide |
| g | - | grab |
| t | - | throw |
| q | - | quit |
The simulation should begin in an octopus' garden. The octopus lets Ringo in, knows where he's been, etc, but then begins mauling him with over-ripe sea cucumbers and carrotfish. Ringo can only escape the garden-fresh barrage by (g)rabbing the octopus, (t)hrowing it on the ground, and then swimming away (n, s, e, or w), in that order. Failing to execute the steps in the proper order, one immediately after the other, should result in a face full of vegetables. Note that, although the directional swimming commands are necessary to escape the octopus, you don't need to worry about keeping track of Ringo's location other than whether or not he is in the garden.
Example:
% a.out You're in an octopus' garden, just like in your song, except the octopus is throwing things at you and frightening you. Your action: e You try to swim east, but the octopus gets in your way. The octopus keeps harassing you. Your action: t You try to throw something, but you have nothing in your hands. The octopus keeps harassing you. Your action: g You grab the octopus with your mighty European arms. Your action: y You yell at the octopus, "go watch TV!" The octopus wriggles free of your grasp. The octopus keeps harassing you. 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: h You try to hide, but there is nothing to hide behind. The octopus recovers from its fall. The octopus keeps harassing you. 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, finally free of the octopus' garden. Your action: q You quit, weary of undersea life already.
Have your program simulate a region to the east of the octopus' garden, filled with electric eels, and a region to the north of that, containing a crab. If Ringo grabs the electric eels, he gets several kwH of free electric power for his jam box (free electric power is the only good thing Ringo will find under the sea), but if he grabs the crab, it will cut him and leave a scab.
Example:
% a.out You're in an octopus' garden, just like in your song, except the octopus is throwing things at you and frightening you. 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: g You grab some eels. Their ultra-conductive skin makes them very slippery and painful to hold, but the thought of all that free electricity strengthens your grip. Your action: n You swim north, away from the electric eels. There is a crab here. Your action: g You grab the crab. This will taste good with a Diet Coke, or a Tab. Your action: q You quit, weary of undersea life already.
Location Move ( Location start, char direction ) ;
which takes an enumerated location type for the starting location and a character representing the direction of movement (using the first letter of the direction, as in the user interface command), and returns the resulting location. The behavior of the program should not change from the version in problem 2, however.