コード例 #1
0
        private TicTacToeResult Diagonal()
        {
            //first 3x3 diagonal
            var diagonal1Result = new DirectionResult();

            for (int coordinate = 0; coordinate <= 2; coordinate++)
            {
                diagonal1Result.InspectBoardCoordinate(_board[coordinate, coordinate], coordinate, coordinate);
            }
            if (diagonal1Result.IsThereAWinner())
            {
                return(new TicTacToeResult(GameResultType.Winner, diagonal1Result.Name, diagonal1Result.Coordinates));
            }

            //second 3x3 diagonal
            var diagonal2Result = new DirectionResult();
            int column          = 2;

            for (int row = 0; row <= 2; row++)
            {
                diagonal2Result.InspectBoardCoordinate(_board[row, column], row, column);
                column--;
            }
            if (diagonal2Result.IsThereAWinner())
            {
                return(new TicTacToeResult(GameResultType.Winner, diagonal2Result.Name, diagonal2Result.Coordinates));
            }

            return(new TicTacToeResult(GameResultType.NoWinner, string.Empty, string.Empty));
        }
コード例 #2
0
        private TicTacToeResult Horizontal()
        {
            for (int row = 0; row <= 2; row++)
            {
                var directionResult = new DirectionResult();

                for (int column = 0; column <= 2; column++)
                {
                    directionResult.InspectBoardCoordinate(_board[row, column], row, column);
                }
                if (directionResult.IsThereAWinner())
                {
                    return(new TicTacToeResult(GameResultType.Winner, directionResult.Name, directionResult.Coordinates));
                }
            }
            return(new TicTacToeResult(GameResultType.NoWinner, string.Empty, string.Empty));
        }