Adapt the Use method to switch the torch on and off

From TRCCompSci - AQA Computer Science
Revision as of 15:32, 18 December 2018 by Admin (talk | contribs) (Created page with "The torch has a status of "lightable" and also "off". So can we switch on the torch instead of just writing out that it is now easier to see. =Current Use method= <syntaxhig...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The torch has a status of "lightable" and also "off". So can we switch on the torch instead of just writing out that it is now easier to see.

Current Use method

 private static void UseItem(List<Item> items, string itemToUse, int currentLocation, ref bool stopGame, List<Place> places)
        {
            int position, indexOfItem;
            string resultForCommand, subCommand = "", subCommandParameter = "";
            indexOfItem = GetIndexOfItem(itemToUse, -1, items);
            if (indexOfItem != -1)
            {
                if (items[indexOfItem].Location == Inventory || (items[indexOfItem].Location == currentLocation && items[indexOfItem].Status.Contains("usable")))
                {
                    position = GetPositionOfCommand(items[indexOfItem].Commands, "use");
                    resultForCommand = GetResultForCommand(items[indexOfItem].Results, position);
                    ExtractResultForCommand(ref subCommand, ref subCommandParameter, resultForCommand);
                    if (subCommand == "say")
                    {
                        Say(subCommandParameter);
                    }
                    else if (subCommand == "lockunlock")
                    {
                        int IndexOfItemToLockUnlock, IndexOfOtherSideItemToLockUnlock;
                        IndexOfItemToLockUnlock = GetIndexOfItem("", Convert.ToInt32(subCommandParameter), items);
                        IndexOfOtherSideItemToLockUnlock = GetIndexOfItem("", Convert.ToInt32(subCommandParameter) + IDDifferenceForObjectInTwoLocations, items);
                        ChangeStatusOfDoor(items, currentLocation, IndexOfItemToLockUnlock, IndexOfOtherSideItemToLockUnlock);
                    }
                    else if (subCommand == "roll")
                    {
                        Say("You have rolled a " + RollDie(resultForCommand[5].ToString(), resultForCommand[7].ToString()));
                    }
                    return;
                }
            }
            Console.WriteLine("You can't use that!");
        }