コード例 #1
0
ファイル: Program.cs プロジェクト: RyanBreaker/TicTacToe
        static void Main(string[] args)
        {
            var    grid = new Grid();
            string input;

            const string TRYAGAIN = "Try again.";

            int x, y;

            // Game loop
            while (grid.playing)
            {
                // Show grid to players
                Console.WriteLine(grid.ToString());

                // Get player move and check the input; see regex for current format
                input = Console.ReadLine().ToUpper();
                if (!(input.Length == 3 && Regex.IsMatch(input, "^([0-2]{2})(X|O)$")))
                {
                    Console.WriteLine(TRYAGAIN);
                    continue;
                }

                // Plugin input
                x = int.Parse(input[0].ToString());
                y = int.Parse(input[1].ToString());

                // Set the spot, returns false if spot is already set or given wrong input
                if (!grid.setSpot(new Spot(x, y), (Pieces)input[2]))
                {
                    Console.WriteLine(TRYAGAIN);
                    continue;
                }
            }

            // Game is over when execution gets here
            Console.WriteLine("Game is over!");
            Console.WriteLine("Result: " + grid.result);
            Console.WriteLine(grid.ToString());

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: RyanBreaker/TicTacToe
        static void Main(string[] args)
        {
            var grid = new Grid();
            string input;

            const string TRYAGAIN = "Try again.";

            int x, y;

            // Game loop
            while (grid.playing)
            {
                // Show grid to players
                Console.WriteLine(grid.ToString());

                // Get player move and check the input; see regex for current format
                input = Console.ReadLine().ToUpper();
                if (!(input.Length == 3 && Regex.IsMatch(input, "^([0-2]{2})(X|O)$")))
                {
                    Console.WriteLine(TRYAGAIN);
                    continue;
                }

                // Plugin input
                x = int.Parse(input[0].ToString());
                y = int.Parse(input[1].ToString());

                // Set the spot, returns false if spot is already set or given wrong input
                if (!grid.setSpot(new Spot(x, y), (Pieces)input[2]))
                {
                    Console.WriteLine(TRYAGAIN);
                    continue;
                }
            }

            // Game is over when execution gets here
            Console.WriteLine("Game is over!");
            Console.WriteLine("Result: " + grid.result);
            Console.WriteLine(grid.ToString());

            Console.ReadLine();
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: alinddicu/TicTacToe
        public void Run()
        {
            for (var i = 0; ; i++)
            {
                _output("Grid layout:");
                _output(_grid.ToString());
                var activePlayer = _players[i % 2];
                GetPositionForActivePlayer(activePlayer);
                if (!_victoryPossibilities.IsWinning(activePlayer))
                {
                    continue;
                }

                _output($"Player {activePlayer} won!!!");
                break;
            }

            _output("Grid layout:");
            _output(_grid.ToString());
            _input();
        }
コード例 #4
0
 public override string ToString()
 {
     return(_grid.ToString());
 }