Homework #7
Due Friday, April 6th at 5pm
Note: bold text in the examples is input from the user.
Big deal, right? Well hold on, if you've implemented your simulator the way you were told (with a Move function that just takes a Location type as input), you won't be able to put the same Location type in more than one area of the map without eliciting bizzarre `teleportation' behavior whenever Ringo leaves one of the areas. This is because the Move function has no way of knowing which of the identical Locations Ringo is actually in, so it just picks the first one it finds in every case.
But you also don't want to have a different Location type for every stretch of water in the ocean, or you'll needlessly complicate your other functions with separate cases for identical locations. What the simulator needs in this case is a Move function that takes and returns a pair of x and y coordinates rather than a Location type, so it can distinguish identical places on the map without requiring their descriptions to be unique. In order to send and return all this information at once, you'll need to use (instead of the basic Location type) an ObjectInfo structure for Ringo's location containing two integers for the x and y coordinates on the simulation map as well as an enumerated State type for the special places (such as `Ringo's hand' and `the floor') that were formerly represented as non-map Locations. Since we might want more than just Ringo to move around in the future, also add a field for the enumerated type or #define'd integer that you use to identify game objects. A prototype for the new Move function is shown below.
ObjectInfo Move ( ObjectInfo object, char direction, Location map [5][5] ) ;
Example:
% a.out You are 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: w You swim west, out of the octopus' garden, into the pointy rocks. Your action: n You swim north, out of the pointy rocks, into the prawn shop. Your action: n You swim north, out of the prawn shop, into the water. Your action: s You swim south, out of the water, into the prawn shop. Your action: s You swim south, out of the prawn shop, into the pointy rocks. Your action: s You swim south, out of the pointy rocks, into the sunken pirate ship. Your action: w You swim west, out of the sunken pirate ship, into the water. Your action: e You swim east, out of the water, into the sunken pirate ship. Your action: q You quit, bored of undersea life already.
void Grab ( ObjectInfo objects [100] ) ; void Throw ( ObjectInfo objects [100] ) ;
Example:
% a.out You are 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: n You swim north, out of the octopus' garden, into the brine & spirits shop. Your action: e You swim east, out of the brine & spirits shop, into the crab's cottage. Your action: g You grab the crab. Its hair is pretty but its clothes are drab. Your action: w You swim west, out of the crab's cottage, into the brine & spirits shop. Your action: w You swim west, out of the brine & spirits shop, into the prawn shop. Your action: n You swim north, out of the prawn shop, into the water. Your action: t You throw the crab to the floor. There is a crab here. Your action: g You grab the crab. You hope it takes you to its secret lab. Your action: s You swim south, out of the water, into the prawn shop. Your action: s You swim south, out of the prawn shop, into the pointy rocks. Your action: s You swim south, out of the pointy rocks, into the sunken pirate ship. Your action: w You swim west, out of the sunken pirate ship, into the water. Your action: t You throw the crab to the floor. There is a crab here. Your action: g You grab the crab. Its vest conceals a roll of hidden flab. Your action: q You quit, bored of undersea life already.
This is where you get your sweet reward for using a function to control Ringo's movement. Each turn, before carrying out Ringo's move, simply pick a direction (north, south, east, or west) that leads away from Ringo's current location, and call the Move function using the ObjectInfo structure for the crab (if Ringo is not already weilding it) instead for Ringo. You should also set up a conditional in the Move function to produce object-specific update messages, as shown in the example below.
Example:
% a.out You are in the octopus' garden again. Your action: g You grab the octopus with your mighty European arms. The crab swims north, out of the crab's cottage, into the spooky sinkhole. Your action: t You throw the octopus onto the ground. It is momentarily dazed. The crab swims east, out of the spooky sinkhole, into Micky Dolens' locker. Your action: n You swim north, out of the octopus' garden, into the brine & spirits shop. The crab tries to swim east, out of Micky Dolens' locker, but the current draws it back. Your action: q You quit, bored of undersea life already.