コード例 #1
0
ファイル: Program.cs プロジェクト: TaylorOne/TicTacToe
        static void Main()
        {
            Random rando   = new Random();
            bool   quit    = false;
            bool   endgame = false;
            bool   success;

            Game game = new Game();

            Console.WriteLine("TIC TAC TOE\n\n");
            while (!quit)
            {
                game.Reset();

                while (game.CheckStatus() == GameStatus.Playing)
                {
                    game.DrawBoard();
                    endgame = false;

                    do
                    {
                        success = game.UpdateBoard(HumanTurn(), 'X');
                        if (!success)
                        {
                            Console.WriteLine("That spot is already taken!");
                        }
                    }while (!success);

                    if (game.CheckStatus() == GameStatus.Win)
                    {
                        game.DrawBoard();
                        quit    = EndgameMenu(GameStatus.Win);
                        endgame = true;
                    }
                    else if (game.CheckStatus() == GameStatus.Loss)
                    {
                        game.DrawBoard();
                        quit    = EndgameMenu(GameStatus.Loss);
                        endgame = true;
                    }
                    else if (game.CheckStatus() == GameStatus.Draw)
                    {
                        game.DrawBoard();
                        quit    = EndgameMenu(GameStatus.Draw);
                        endgame = true;
                    }

                    if (!quit & !endgame)
                    {
                        game.AIturn();

                        if (game.CheckStatus() == GameStatus.Win)
                        {
                            game.DrawBoard();
                            quit = EndgameMenu(GameStatus.Win);
                        }
                        else if (game.CheckStatus() == GameStatus.Loss)
                        {
                            game.DrawBoard();
                            quit = EndgameMenu(GameStatus.Loss);
                        }
                        else if (game.CheckStatus() == GameStatus.Draw)
                        {
                            game.DrawBoard();
                            quit = EndgameMenu(GameStatus.Draw);
                        }
                    }
                }
            }
        }