Program 4 Dordal Due: Nov 19, 2004 You are to modify the game program presented in class, adding the following features: 1. Add a second Lantern, of class Lantern. The second Lantern should have the same name, LANTERN. When the user invokes the command LIGHT LANTERN you look on the Inventory for the first such object and light() it. Note that you will need to downcast from Carryable* to Lantern* to do this. Similarly, in the dark rooms, you will need to check whether there is any Lightable on Inventory (it also has to be lit!). The function haslight() may be useful here, though notice that it doesn't check whether the lantern is lit. Notice also that, as written, it returns only the first Lightable, which may be the "wrong" one! Your program, for example, should work properly even when both LANTERNs are on the Inventory list and only the second one is lit. For a modest amount of extra credit, have some puzzle where it makes a difference which of the two (identically named!) LANTERNs the user has. For example, ... There is a magic inscription at the base, but you'll need to shine the light on it to read it. SHINE LANTERN I'm sorry! You seem to have the dim lantern; somewhere there is the bright lantern though. Note that if the user has both the dim LANTERN and bright LANTERN on Inventory, in that order, then LIGHT LANTERN will light only the first, dim, LANTERN. (Can you figure out how to get the bright LANTERN lit in that situation?) 2. If you eat the chocolate, it should go away after 2-3 bites. Keep the number of bites left as an attribute of the chocolate itself. To do this, you will need to create a class Eatable : public Carryable { private: int _bitesleft; public: bool eat() { if (!_bitesleft) return false; else _bitesleft --; } or something like that. You won't need downcasting if there is only one Eatable thing in the game (CHOCOLATE). 3. Introduce a puzzle room where you cannot *leave* the room until some action occurs. Possibilities are: You have to FIGHT the dragon (with a SWORD?) You have to GIVE the dragon a PRESENT or COOKIE. There is a cave-in and you have to DIG (with SHOVEL?) 4. Introduce a class DarkRoom (intended to apply to the cave area, but possibly to the Hollow Tree as well). In a DarkRoom, the following rules apply: 1. You cannot go from one DarkRoom to another without a light. 2. On entry to a DarkRoom, if you don't have a light you are warned to get one! 3. If you don't *leave* the DarkRoom by the second turn, or turn a Lightable on, a "grue" will get you and you die. DarkRoom should keep a counter of the number of times DarkRoom::response() is called, reset to 0 by DarkRoom::onentry(). 4. If you do have a light with you, DarkRoom behaves exactly the same as Room. 5. Note that it is possible to DROP the light, in which case the Dark rules again should be in force. Make all cave passages DarkRooms. (You may need to add some extra cave.) Note that this involves changing the parent structure: the existing StoneRoom will now have DarkRoom rather than Room as a parent. Note also that DarkRoom may have its behavior overridden by, say, StoneRoom; this is probably not a serious difficulty in practice. 5. You are to add one additional puzzle of your own. Your puzzle should, at a minimum, involve the following: one new CarryObj one new verb one new derived room class, with special behavior for at least one verb (new or existing). some kind of state change to the room or to an object (like the stone being moved or valve being turned) You will be graded in part on the inventiveness of your puzzle. Here are a few possibilities. UNLOCK CHEST with a KEY found elsewhere; once the chest is unlocked, something should be inside. Cross a rickety two-move bridge over a bottomless pit; if you carry too much the bridge will break; you can only carry two things at a time. You need to CAST SPELL in the WizardsChamber, but in order to do this you must first find in the game a BELL, BOOK, and CANDLE. (And maybe LIGHT CANDLE? Or maybe, in the simpler direction, just find NEWTEYE and BATWING. If you try to CAST SPELL and don't have the ingredients, the game should tell you what you're missing.) Be sure all verbs you introduce are handled at some primitive level by Room::response(), so that they're not completely unrecognized even if you're not in the "right" room.