Beispiel #1
0
        private void AIMove()
        {
            int botMove = AI.AIMove();

            zonesBttn[botMove].Content    = Player2Symbol;
            zonesBttn[botMove].Foreground = Player2Symbol == 'X' ? Brushes.Red : Brushes.Blue;
            int[] winPos = ProgrammLogics.CheckWin(Zones(), botMove);

            if (winPos != null)
            {
                Brush prevColor = zonesBttn[0].Background;

                foreach (int w in winPos)
                {
                    zonesBttn[w].Background = Brushes.Green;
                }

                MessageBox.Show("Computer Win!", "Game Over");
                IncrementComputerWins();

                foreach (int w in winPos)
                {
                    zonesBttn[w].Background = prevColor;
                }

                ClearPlayField();

                if (!IsPlayer1FirstMove)
                {
                    AIMove();
                }

                return;
            }
            else if (ProgrammLogics.CheckDraw(Zones()))
            {
                MessageBox.Show("Draw!", "Game Over");
                ClearPlayField();
                IncrementDraws();

                if (!IsPlayer1FirstMove)
                {
                    AIMove();
                }
            }
        }