Example #1
0
        private void cellButton_Click(object sender, EventArgs e)
        {
            if (!m_Game.isComputerTurn)
            {
                bool correct = false;
                if (!m_Game.IsGuessesInit())
                {
                    correct = m_Game.SetGuess((sender as CellButton).RowIndex, (sender as CellButton).ColumnIndex);
                    (sender as CellButton).InCheck = m_Game.IsCellInCheck((sender as CellButton).RowIndex, (sender as CellButton).ColumnIndex);
                    handleFirstClick();
                }
                else
                {
                    correct = m_Game.SetGuess((sender as CellButton).RowIndex, (sender as CellButton).ColumnIndex);
                    (sender as CellButton).InCheck = m_Game.IsCellInCheck((sender as CellButton).RowIndex, (sender as CellButton).ColumnIndex);
                    handleSecondClick(correct);

                    if (m_Game.IsNewTurn())
                    {
                        m_Game.ClearTurn(correct);
                        updateLabels();
                    }
                }

                while (m_Game.isComputerTurn && !m_Game.IsGameFinished())
                {
                    computerPlay();
                }

                if (m_Game.IsGameFinished())
                {
                    handleGameOver();
                }
            }
        }