Exemple #1
0
        void cellClick(Object sender, EventArgs e)
        {
            Button currentCell = (Button)sender;

            if (!isEmpty(currentCell) || game.getBoard().getIndexValue(Convert.ToInt32(currentCell.Name)) != 0)
            {
                MessageBox.Show("This cell is already occupied", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                if (playerTurn == 1)
                {
                    currentCell.Text      = "X";
                    currentCell.Tag       = "1";
                    currentCell.BackColor = Color.Green;
                    game.getBoard().setIndex(Convert.ToInt32(currentCell.Name), playerOne);
                    if (checkWin(playerTurn) == 1)
                    {
                        MessageBox.Show("Player one is the Winner!!!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        resetGame();
                        game.getBoard().resetBoard();
                        playerTurn = 1;
                        return;
                    }
                    playerTurn = 2;
                    if (playerTwo.makeStrategyMove() && playerTurn == 2)
                    {
                        markOpponentMove();
                        playerTwo.printEvaluatedBoard();
                        checkWin(playerTurn);
                        if (checkWin(playerTurn) == 2)
                        {
                            MessageBox.Show("Player two is the Winner!!!", "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            resetGame();
                            game.getBoard().resetBoard();
                            playerTwo.makeStrategyMove();
                            markOpponentMove();
                            playerTurn = 1;
                            return;
                        }
                        playerTurn = 1;
                    }
                }
            }
        }