Exemplo n.º 1
0
 static public void Parse(List <string> twoWord)
 {
     Console.WriteLine("");
     if (validTwoWordCommands.Contains(twoWord[0]))
     {
         List <string> accessible = Prompt.AccessibleItems();
         if (!accessible.Contains(twoWord[1]))
         {
             Console.WriteLine($"No such item available.");
         }
         else
         {
             Item item = Item.byName[twoWord[1]];
             if (twoWord[0] == "examine")
             {
                 Examine(ref item);
             }
             if (twoWord[0] == "take")
             {
                 Take.Act(ref item);
             }
             if (twoWord[0] == "open")
             {
                 Access.Open(ref item);
             }
             if (twoWord[0] == "drop")
             {
                 Take.Drop(ref item);
             }
             if (new string[] { "turnon", "play" }.Contains(twoWord[0]))
             {
                 Access.TurnOn(ref item);
             }
             if (new string[] { "turnoff", "blowout" }.Contains(twoWord[0]))
             {
                 Access.TurnOff(ref item);
             }
             if (new string[] { "unlock" }.Contains(twoWord[0]))
             {
                 Access.Unlock(ref item);
             }
             if (new string[] { "eat", "drink" }.Contains(twoWord[0]))
             {
                 Take.Eat(ref item);
             }
             if (new string[] { "close" }.Contains(twoWord[0]))
             {
                 Access.Close(ref item);
             }
         }
     }
     else if (MultiWordCommands.validMultiWordCommands.Contains(twoWord[0]))
     {
         MultiWordCommands.Parse(twoWord);
     }
     else
     {
         Console.WriteLine("Invalid Command");
     }
 }
Exemplo n.º 2
0
 static public void Ask() // Parses the user input
 {
     if (Program.winCondition)
     {
         ;
     }                           // skips to victory screen if you've already won
     else if (Program.turns > 0) // checks if you have any turns remaining
     {
         string command = "";
         if (Program.wantReset && Program.resetStep < Program.saveFile.Count)
         {
             command = Program.saveFile[Program.resetStep];
             Console.WriteLine($"> {command}");
             Program.currentLog.Add(command);
             Program.resetStep++;
             Program.turns--;
             if (Program.resetStep >= Program.saveFile.Count)
             {
                 Program.wantReset = false;
             }
         }
         else
         {
             while (String.IsNullOrWhiteSpace(command))
             {
                 Console.Write($"\nYou have {Program.turns} turns left. What would you like to do? ");
                 command = Console.ReadLine().ToLower();
                 Program.turns--;
                 Program.currentLog.Add(command);
                 if (Program.turns < 1)
                 {
                     break; // ends loop if you're out of turns
                 }
             }
         }
         if (!String.IsNullOrWhiteSpace(command))
         {
             List <string> commands = new List <string>(command.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
             TranslateInput(ref commands);
             if (command == "insert batteries into flashlight")
             {
                 Temp_Four_Word_Commands.InsertBatteriesInToFlashlight();
             }
             else if (command == "insert batteries into tapedeck")
             {
                 Temp_Four_Word_Commands.InsertBatteriesInToTapeDeck();
             }
             else if (command == "insert batteries into tape deck")
             {
                 Temp_Four_Word_Commands.InsertBatteriesInToTapeDeck();
             }
             else if (command == "insert batteries into tape player")
             {
                 Temp_Four_Word_Commands.InsertBatteriesInToTapeDeck();
             }
             else if (commands.Count == 1)
             {
                 OneWordCommands.Parse(commands);
             }
             else if (commands.Count == 2)
             {
                 TwoWordCommands.Parse(commands);
             }
             else
             {
                 MultiWordCommands.Parse(commands);
             }
             Ask();
         }
     }
     else
     {
         Console.WriteLine("No turns left!");
     }
 }
Exemplo n.º 3
0
 static public void Parse(List <string> oneWord)
 {
     if (validOneWordCommands.Contains(oneWord[0]))
     {
         if (oneWord[0] == "win")
         {
             Win();                      // does series of if/else if checkes to determine which method to operate
         }
         else if (oneWord[0] == "explore")
         {
             Explore();
         }
         else if (oneWord[0] == "inventory")
         {
             Inventory();
         }
         else if (oneWord[0] == "move")
         {
             Move();
         }
         else if (oneWord[0] == "access")
         {
             Access();
         }
         else if (oneWord[0] == "save")
         {
             Save();
         }
         else if (oneWord[0] == "load")
         {
             Load();
         }
         else if (oneWord[0] == "help")
         {
             Help();
         }
         else
         {
             Console.WriteLine("Invalid command!");
         }
     }
     else if (TwoWordCommands.validTwoWordCommands.Contains(oneWord[0]) || MultiWordCommands.validMultiWordCommands.Contains(oneWord[0]))
     {
         Console.Write($"{oneWord[0]} what? "); // asks for more works if command is recognized but not complete
         List <string> commands = new List <string>(Console.ReadLine().ToLower().Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
         Prompt.TranslateInput(ref commands);
         if (oneWord[0] != commands[0])
         {
             commands.Insert(0, oneWord[0]);                            // checcks to see if original verb was repeated
         }
         if (commands.Count == 1)
         {
             Parse(commands);
         }
         else if (commands.Count == 2)
         {
             TwoWordCommands.Parse(commands);
         }
         else
         {
             MultiWordCommands.Parse(commands);
         }
     }
     else
     {
         Console.WriteLine("Invalid Command");
     }
 }