Example #1
0
        public void Run()
        {
            Player player = Player.X;
            Player?winner = null;

            do
            {
                Tuple <int, int> move;
                try {
                    move = io.AskNextMove(player, board);
                } catch {
                    io.DisplayError(GameError.CouldNotParseMove);
                    continue;
                }

                if (!ValidateMove(move))
                {
                    io.DisplayError(GameError.CouldNotParseMove);
                    continue;
                }

                try {
                    board[move.Item1, move.Item2] = player;
                } catch (InvalidOperationException) {
                    io.DisplayError(GameError.CellAlreadyOccupied);
                    continue;
                }

                player = GetNextPlayer(player);
                winner = analyzer.DetermineWinner(board);
            } while (!winner.HasValue);

            io.DisplayWinner(winner.Value);
        }