Menu

Iteration 4 – Looking In this iteration you will add the first of the commands, the look command. This will give you sufficient conde th create a small annlication where the ucer can lnnk at item

Iteration 4 – Looking In this iteration you will add the first of the commands, the look command. This will give you sufficient conde th create a small annlication where the ucer can lnnk at items thev have AS there will be a number of commanas, an abstract commana class nas also been adaed. This class inherits from Identifiable Object, as each of the commands needs to be identifiable. When data is entered by the user, each Command object will be asked “Are You” and the first work of the command. For example, with “look at pen” each Command would be asked “Are You ‘look’ ” to locate the Command to process the text. As a result the Look Command should be identified by “look”. Object Oriented Programming Swin-Adventure C\# Implementation Plan The Look Command will handle the instructions like: look at pen in bag look at bag in inventory look at pen look at bag look at pen in bag look at bag in inventory look at pen look at bag To handle this the Look Command will need to perform a set of action: 1. Locate the “container” where the item resides. For example the bag in “look at pen in bag”, or the player in “look at pen”. – Return “I cannot find the <>” if the container cannot be found. For example, “look at pen in bag” may return “I cannot find the bag”. 2. Locate the item from the “container” – Return “I cannot find the <> in the <> ” if the item cannot be found. For example, “look at pen in bag” may return “I cannot find the pen in the small bag” (in this case “small bag” is the name of the Bag container). 3. Return the full description of the Game Object found. For this to work the code needs a way of treating Bags and Players in the same way: as objects that container other items. To handle this the I Have Inventory interface/protocol has been added. Objects that implement this must be able to perform the following tasks for the Look Command: – Locate and item given its id. Once the container is located from the Player, it is then asked to locate the item from the text id the user entered. – The container needs to be able to return its Name. This can then be used when the item cannot be found in the container. The command input will be supplied as a list of individual words. For example: “look at pen in bag” will be passed in as the list [ “look”, “at”, “pen”, “in”, “bag” ]. The conversion of the text from a single string to a list will be handled elsewhere. Processing the array will be performed as follows: 1. There must be either 3 or 5 elements in the array, otherwise return “I don’t know how to look like that” 2. The first word must be “look”, otherwise return “Error in look input” 3. The second word must be “at”, otherwise return “What do you want to look at?” 4. If there are 5 elements, then the 4 th word must be “in”, otherwise return “What do you want to look in?” 5. If there are 3 elements, the container is the player 6. If there are 5 elements, then the container id is the 5 th word 1. Call FetchContainer, and have this method retrieve the container from the Player. 7. The item id is the 3rd word 8. Perform the look at in, with the container and the item id Page 9 of 15

OR