Example #1
0
        public static void RecieveInput(Game game)
        {
            String prompt = "Current turn: " + (game.NumOfTurns() + 1) + ". ";

            prompt += game.BlackTurn() ? "Black's turn: " : "White's turn: ";
            Console.WriteLine(prompt);
            String input = Console.ReadLine();

            if (input == "<")
            {
                if (!game.UndoTurnChecked())
                {
                    Console.Write("Cannot Take Back. ");
                    RecieveInput(game);
                }
                else
                {
                    Console.Write("Took Back.\n");
                }
            }
            else if (input == ">")
            {
                if (!game.GoForwardChecked())
                {
                    Console.Write("Cannot Go Forward. ");
                    RecieveInput(game);
                }
                else
                {
                    Console.Write("Went forward.\n");
                }
            }
            else if (input != "" && input[0] == '/')
            {
                try {
                    int num = Int16.Parse(input.Remove(0, 1));
                    if (!game.GoToChecked(num - 1))
                    {
                        Console.Write("Cannnot Go To. ");
                        RecieveInput(game);
                    }
                    else
                    {
                        Console.Write("Went To.\n");
                    }
                }
                catch (FormatException) {
                    Console.Write("Invalid. ");
                    RecieveInput(game);
                }
            }
            else
            {
                try {
                    int num = Int16.Parse(input);
                    if (!game.DoTurnChecked(num - 1))
                    {
                        Console.Write("Invalid. ");
                        RecieveInput(game);
                    }
                    else
                    {
                        Console.Write("Turn made.\n");
                    }
                }
                catch (FormatException) {
                    Console.Write("Invalid. ");
                    RecieveInput(game);
                }
            }
        }