Esempio n. 1
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");
     }
 }
Esempio n. 2
0
        static public bool Unlock(ref Item item)
        {
            string   name = item.dictName;
            Location room = Location.CurrentRoom;

            if (!item.canLock)
            {
                Console.WriteLine("There's no lock.");
                return(false);
            }
            if (!item.isLocked)
            {
                Console.WriteLine("It's already unlocked.");
                return(false);
            }
            if (item.unlockCodes.Count > 0)
            {
                string attempt = "bad";
                bool   cheat   = false;
                do
                {
                    Console.WriteLine($"You must enter a four digit combination.  {Program.turns} turns left.");
                    Console.Write("Or you can 'quit' > ");
                    attempt        = Console.ReadLine();
                    Program.turns -= 1;
                    if (item.unlockCodes.Contains(attempt) && !item.comboKnown)
                    {
                        Console.WriteLine("You feel that should have worked...  maybe you typed it in wrong.");
                        cheat = true;
                    }
                }while (attempt.ToLower() != "quit" && !cheat && Program.turns > 0 && !item.unlockCodes.Contains(attempt));
                if (attempt.ToLower() == "quit" || Program.turns == 0)
                {
                    Console.WriteLine("You failed!");
                    Console.WriteLine("Which is strange, because you felt like that should have worked.  Maybe you typed it in wrong?");
                    return(false);
                }
                else
                {
                    Console.WriteLine($"{item.commonDescription} is now unlocked");
                    item.isLocked = false;
                    return(true);
                }
            }
            else if (item.unlockItems.Count > 0)
            {
                Console.WriteLine("With what? ");
                Console.Write(">  ");
                string        answer = Console.ReadLine();
                List <string> arr    = new List <string>(answer.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
                Prompt.TranslateInput(ref arr);
                if ((arr.Count > 0 && item.unlockItems.Contains(arr[0])) || (arr.Count > 1 && item.unlockItems.Contains(arr[1])))
                {
                    if (Player.inventory.Contains("studyroomkey"))
                    {
                        Console.WriteLine("\nYou've successfully opened the door.\n");
                        Console.WriteLine("Congratulations on making it through the first room!  More to come soon!\n");
                        Program.winCondition = true;
                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("You don't have a key.");
                        return(false);
                    }
                }
                else
                {
                    Console.WriteLine("That won't work.");
                    return(false);
                }
            }
            return(false);
        }