internal void SetPlayers(string i_Player1Name, string i_Player2Name)
        {
            byte playerIndex;
            byte otherPlayerIndex;

            getRandomPlayersOrder(out playerIndex, out otherPlayerIndex);
            this.Players[playerIndex] = new Player(ePlayerType.Human, eSign.X)
            {
                m_Name = i_Player1Name
            };
            if (this.m_GameType == eGameType.PersonVsPerson)
            {
                this.Players[otherPlayerIndex] = new Player(ePlayerType.Human, eSign.O)
                {
                    m_Name = i_Player2Name
                };
            }
            else
            {
                // PersonVsComputer
                this.Players[otherPlayerIndex] = new Player(ePlayerType.Computer, eSign.O)
                {
                    m_Name = "Computer"
                };
                this.m_AIEngine = new AIEngine(this);
            }
        }
Exemple #2
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]);
     }
 }
Exemple #3
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]);
            }
        }