Beispiel #1
0
 /// <summary>
 /// Resets the game board.
 /// </summary>
 public void Reset(bool computerStart = false, bool playAsX = true)
 {
     isFinished                 = false;
     this.GameBoard             = new GameBoard();
     this.GameBoard.CurrentTurn = (computerStart != playAsX) ? 'X' : 'O';
     this.playAsX               = playAsX;
     this.ComputerStart         = computerStart;
     message.Text               = "";
     if (computerStart)
     {
         int[] move = AIEngine.GetNextMove(this.GameBoard);
         Mark(move[0], move[1]);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Receives click information from the form and acts on the GameBoard, marking the appropriate
        /// place.
        /// </summary>
        /// <param name="x">The x coordinate of the click.</param>
        /// <param name="y">The y coordinate of the click.</param>
        public void ProcessClick(int x, int y)
        {
            if (isFinished)
            {
                return;
            }
            int unitX      = this.Width / 3;
            int unitY      = this.Height / 3;
            int convertedX = x / unitX;
            int convertedY = y / unitY;

            convertedX = (convertedX > 2) ? 2 : convertedX;
            convertedY = (convertedY > 2) ? 2 : convertedY;

            Mark(convertedX, convertedY);

            if (!isFinished)
            {
                int[] move = AIEngine.GetNextMove(gameBoard);
                Mark(move[0], move[1]);
            }
        }