Add to the examine method the ability to examine the room, ie to repeat the description and items

From TRCCompSci - AQA Computer Science
Revision as of 12:44, 13 December 2018 by Admin (talk | contribs) (Created page with "=The Examine method= There is already a method to examine the inventory or an item so find this code: <syntaxhighlight lang=c#> private static void Examine(List<Item> items,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Examine method

There is already a method to examine the inventory or an item so find this code:

private static void Examine(List<Item> items, List<Character> characters, string itemToExamine, int currentLocation)
        {
            int Count = 0;
            if (itemToExamine == "inventory")
            {
                DisplayInventory(items);
            }
            else

An if statement controls if it is the inventory or an item which is examined. We can change this if statement to also add the room, by adding an "else if" into this if statement. So change the code to the code below:

private static void Examine(List<Item> items, List<Character> characters, string itemToExamine, int currentLocation)
        {
            int Count = 0;
            if (itemToExamine == "inventory")
            {
                DisplayInventory(items);
            }
            else if (itemToExamine == "room")
            {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine(places[characters[0].CurrentLocation - 1].Description);
                    DisplayGettableItemsInLocation(items, characters[0].CurrentLocation);
            }
            else

The code to write the room description in the else if is lifted from the PlayGame method.