コード例 #1
0
ファイル: Program.cs プロジェクト: pinieb/tanya
        static void Main(string[] args)
        {
            // This class should be treated as read-only for your purposes, but feel free to see how it works
            Board game = new Board();

            int player = 2;

            while (!game.IsWinningBoard() && !game.IsCatsGame())
            {
                player = player % 2 + 1; // change the players
                Console.Out.Write("Input the square number for player " + player + "'s move: ");
                string squareAsString = Console.In.ReadLine();
                int square;
                while (!Int32.TryParse(squareAsString, out square) && square >= 1 && square <= 9)
                {
                    Console.Out.WriteLine("An invalid square was entered, please try again.");
                    Console.Out.Write("Input the square number for player " + player + "'s move: ");
                    squareAsString = Console.In.ReadLine();
                }

                game.PrintBoard();
            }

            if (game.IsWinningBoard())
            {
                Console.Out.WriteLine("Player " + player + " is the winner!");
            }
            else
            {
                Console.Out.WriteLine("Cat's game!");
            }

            Console.ReadKey(); // stop the console from closing automatically
        }