コード例 #1
0
        public void InputHandler()
        {
            try
            {
                while (true)
                {
                    //This creates a user input variable and converts it to all lowecase, allowing capitilizations by the user to be ignored.
                    string userInput = Console.ReadLine().ToLower();


                    //This will check the length and determain what type of input ye want.
                    //It is also reversed, meaning that if the case is 6 it will still check the previus inputs.
                    switch (expectedInput.Length)
                    {
                    case 4:

                        if (expectedInput[0] == userInput || expectedInput[1] == userInput)
                        {
                            Console.BackgroundColor = ConsoleColor.DarkRed;
                            toRed.WriteRoom();
                        }
                        else if (expectedInput[2] == userInput || expectedInput[3] == userInput)
                        {
                            Console.BackgroundColor = ConsoleColor.DarkBlue;
                            toBlue.WriteRoom();
                        }
                        break;

                    case 6:
                        if (expectedInput[4] == userInput || expectedInput[5] == userInput)
                        {
                            Console.BackgroundColor = ConsoleColor.Black;
                            toGreen.WriteRoom();
                        }


                        goto case 4;

                    default:
                        Console.WriteLine("The dev did an oppsie and did not provide an accepted ammount of answers!");
                        break;
                    }
                }
            }
            catch (System.Exception)
            {
                Console.WriteLine("You have reached the end of the game! Press any key to exit.");
                Console.ReadKey();
                Environment.Exit(1); //if i dont do this, the user needs to press ctrl+c the same ammount of times they entered a "room"
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            #region Room definitions

            Room starterRoom = new Room(
                Room.AsciiArt.Title, "You find yourself infront of two buttons. A BLUE and a RED button.",
                "Press the RED button? (r)      Press the BLUE button? (b)",
                "red[]r[]blue[]b"
                );


            Room blueButton1 = new Room(
                Room.AsciiArt.None, "You find yourself infront of two buttons. A BLUE and a RED button. There is a panel that say 'Yes?'.",
                "Press the RED button? (r)      Press the BLUE button? (b)",
                "red[]r[]blue[]b"
                );

            Room redButton1 = new Room(
                Room.AsciiArt.None, "You find yourself infront of two buttons. A BLUE and a RED button. There is a panel that say 'No.'.",
                "Press the RED button? (r)      Press the BLUE button? (b)",
                "red[]r[]blue[]b"
                );

            Room theOnlyButtonThatMatter = new Room(
                Room.AsciiArt.NothingMattered, "Thanks for playing, none of this mattered, I'am lazy so i did not make anything more complicated then this.",
                "Ok (k)      Ok (k)     Play again? (p)",
                "ok[]k[]ok[]k[]play again[]p"
                );

            #endregion

            #region Paths structures
            starterRoom.toRed  = redButton1;
            starterRoom.toBlue = blueButton1;

            redButton1.toRed  = theOnlyButtonThatMatter;
            redButton1.toBlue = blueButton1;

            blueButton1.toRed  = redButton1;
            blueButton1.toBlue = starterRoom;

            theOnlyButtonThatMatter.toGreen = starterRoom;
            #endregion


            Console.Title = "Buttons The Game!";

            //will "start" the game.
            starterRoom.WriteRoom();
        }