示例#1
0
        public void Start()
        {
            var isValidMove = true;

            Console.WriteLine("Welcome to Tic tac toe!");

            while (!board.IsHasWinner() && !board.IsTie())
            {
                if (IsTurnOfPlayerX())
                {
                    Console.WriteLine("\nIt's X player turn");
                    Console.Write("Enter a move: x = ");
                    var x = Convert.ToInt32(Console.ReadLine());
                    Console.Write(" y = ");
                    var y = Convert.ToInt32(Console.ReadLine());

                    var chessPieces = new ChessPieces((char)CHESS_PIECES_TYPE.X, new Vector(x, y));
                    if (board.IsValidMove(chessPieces.Position.X, chessPieces.Position.Y))
                    {
                        isValidMove = true;
                        board.AddAChessPieces(chessPieces);
                    }
                    else
                    {
                        isValidMove = false;
                        Console.WriteLine("Invalid move!");
                    }
                }
                else
                {
                    Console.WriteLine("\nIt's O player turn");
                    Console.Write("Enter a move: x = ");
                    var x = Convert.ToInt32(Console.ReadLine());
                    Console.Write(" y = ");
                    var y = Convert.ToInt32(Console.ReadLine());

                    var chessPieces = new ChessPieces((char)CHESS_PIECES_TYPE.O, new Vector(x, y));
                    if (board.IsValidMove(chessPieces.Position.X, chessPieces.Position.Y))
                    {
                        isValidMove = true;
                        board.AddAChessPieces(chessPieces);
                    }
                    else
                    {
                        isValidMove = false;
                        Console.WriteLine("Invalid move!");
                    }
                }

                Console.WriteLine();
                board.Draw();

                if (isValidMove)
                {
                    turn++;
                }
            }

            Console.WriteLine("\nGame over!");
        }
示例#2
0
        public void AddAChessPieces(ChessPieces chessPieces)
        {
            // check valid move
            var x = chessPieces.Position.X;
            var y = chessPieces.Position.Y;

            if (IsValidMove(x, y))
            {
                ChessPiecesMatrix[x, y] = chessPieces;
                numberOfChessPiecesOnBoard++;
            }
        }
示例#3
0
        public ChessBoard()
        {
            ChessPiecesMatrix = new ChessPieces[3, 3];
            for (var i = 0; i < ChessPiecesMatrix.GetLength(0); i++)
            {
                for (var j = 0; j < ChessPiecesMatrix.GetLength(1); j++)
                {
                    ChessPiecesMatrix[i, j] = new ChessPieces((char)CHESS_PIECES_TYPE.UNKNOWN, new Vector(i, j));
                }
            }

            numberOfChessPiecesOnBoard = 0;
        }