private void Check()// проверка на комбинации кнопок { if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X" && button4.Text == "X" || button7.Text == "X" && button5.Text == "X" && button6.Text == "X" && button8.Text == "X" || button9.Text == "X" && button10.Text == "X" && button11.Text == "X" && button12.Text == "X" || button13.Text == "X" && button14.Text == "X" && button15.Text == "X" && button16.Text == "X" || button1.Text == "X" && button8.Text == "X" && button12.Text == "X" && button16.Text == "X" || button2.Text == "X" && button7.Text == "X" && button11.Text == "X" && button15.Text == "X" || button3.Text == "X" && button6.Text == "X" && button10.Text == "X" && button14.Text == "X" || button4.Text == "X" && button5.Text == "X" && button9.Text == "X" && button13.Text == "X" || button1.Text == "X" && button7.Text == "X" && button10.Text == "X" && button13.Text == "X" || button4.Text == "X" && button6.Text == "X" && button11.Text == "X" && button16.Text == "X" ) { AITimer.Stop(); // остановка таймера компьютера MessageBox.Show("Игрок победил!"); playerWins++; // прибавление к Игроку 1 победы label4.Text = "" + playerWins; //вывод в Label resetGame(); // автоперезапуск уровня } else if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O" && button4.Text == "O" || button7.Text == "O" && button5.Text == "O" && button6.Text == "O" && button8.Text == "O" || button9.Text == "O" && button10.Text == "O" && button11.Text == "O" && button12.Text == "O" || button13.Text == "O" && button14.Text == "O" && button15.Text == "O" && button16.Text == "O" || button1.Text == "O" && button8.Text == "O" && button12.Text == "O" && button16.Text == "O" || button2.Text == "O" && button7.Text == "O" && button11.Text == "O" && button15.Text == "O" || button3.Text == "O" && button6.Text == "O" && button10.Text == "O" && button14.Text == "O" || button4.Text == "O" && button5.Text == "O" && button9.Text == "O" && button13.Text == "O" || button1.Text == "O" && button7.Text == "O" && button10.Text == "O" && button13.Text == "O" || button4.Text == "O" && button6.Text == "O" && button11.Text == "O" && button16.Text == "O") { AITimer.Stop(); MessageBox.Show("Компьютер победил!"); computerWins++;// прибавление к Компьютеру 1 победы label5.Text = "" + computerWins; // resetGame();// см. выше } else if (!(button1.Text == "X" && button2.Text == "X" && button3.Text == "X" && button4.Text == "X" || button7.Text == "X" && button5.Text == "X" && button6.Text == "X" && button8.Text == "X" || button9.Text == "X" && button10.Text == "X" && button11.Text == "X" && button12.Text == "X" || button13.Text == "X" && button14.Text == "X" && button15.Text == "X" && button16.Text == "X" || button1.Text == "X" && button8.Text == "X" && button12.Text == "X" && button16.Text == "X" || button2.Text == "X" && button7.Text == "X" && button11.Text == "X" && button15.Text == "X" || button3.Text == "X" && button6.Text == "X" && button10.Text == "X" && button14.Text == "X" || button4.Text == "X" && button5.Text == "X" && button9.Text == "X" && button13.Text == "X" || button1.Text == "X" && button7.Text == "X" && button10.Text == "X" && button13.Text == "X" || button4.Text == "X" && button6.Text == "X" && button11.Text == "X" && button16.Text == "X") && !(button1.Text == "O" && button2.Text == "O" && button3.Text == "O" && button4.Text == "O" || button7.Text == "O" && button5.Text == "O" && button6.Text == "O" && button8.Text == "O" || button9.Text == "O" && button10.Text == "O" && button11.Text == "O" && button12.Text == "O" || button13.Text == "O" && button14.Text == "O" && button15.Text == "O" && button16.Text == "O" || button1.Text == "O" && button8.Text == "O" && button12.Text == "O" && button16.Text == "O" || button2.Text == "O" && button7.Text == "O" && button11.Text == "O" && button15.Text == "O" || button3.Text == "O" && button6.Text == "O" && button10.Text == "O" && button14.Text == "O" || button4.Text == "O" && button5.Text == "O" && button9.Text == "O" && button13.Text == "O" || button1.Text == "O" && button7.Text == "O" && button10.Text == "O" && button13.Text == "O" || button4.Text == "O" && button6.Text == "O" && button11.Text == "O" && button16.Text == "O")) { } }
private void Check()// проверка на комбинации кнопок { curretPlayer = Player.X; if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X" || button4.Text == "X" && button5.Text == "X" && button6.Text == "X" || button7.Text == "X" && button9.Text == "X" && button8.Text == "X" || button1.Text == "X" && button4.Text == "X" && button7.Text == "X" || button2.Text == "X" && button5.Text == "X" && button8.Text == "X" || button3.Text == "X" && button6.Text == "X" && button9.Text == "X" || button1.Text == "X" && button5.Text == "X" && button9.Text == "X" || button3.Text == "X" && button5.Text == "X" && button7.Text == "X") { AITimer.Stop(); // остановка таймера компьютера MessageBox.Show("Игрок победил!"); playerWins++; // прибавление к Игроку 1 победы label3.Text = "" + playerWins; //вывод в Label resetGame(); // автоперезапуск уровня } else if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O" || button4.Text == "O" && button5.Text == "O" && button6.Text == "O" || button7.Text == "O" && button9.Text == "O" && button8.Text == "O" || button1.Text == "O" && button4.Text == "O" && button7.Text == "O" || button2.Text == "O" && button5.Text == "O" && button8.Text == "O" || button3.Text == "O" && button6.Text == "O" && button9.Text == "O" || button1.Text == "O" && button5.Text == "O" && button9.Text == "O" || button3.Text == "O" && button5.Text == "O" && button7.Text == "O") { AITimer.Stop(); MessageBox.Show("Компьютер победил!"); computerWins++; // прибавление к Компьютеру 1 победы label2.Text = "" + computerWins; resetGame(); // см. выше } else if ((curretPlayer.ToString()) /*&& (!(button1.Text == "O" && button2.Text == "O" && button3.Text == "O" || * * button4.Text == "O" && button5.Text == "O" && button6.Text == "O" || * button7.Text == "O" && button9.Text == "O" && button8.Text == "O" || * button1.Text == "O" && button4.Text == "O" && button7.Text == "O" || * button2.Text == "O" && button5.Text == "O" && button8.Text == "O" || * button3.Text == "O" && button6.Text == "O" && button9.Text == "O" || * button1.Text == "O" && button5.Text == "O" && button9.Text == "O" || * button3.Text == "O" && button5.Text == "O" && button7.Text == "O"))&&( * !(button1.Text == "X" && button2.Text == "X" && button3.Text == "X" || * button4.Text == "X" && button5.Text == "X" && button6.Text == "X" || * button7.Text == "X" && button9.Text == "X" && button8.Text == "X" || * button1.Text == "X" && button4.Text == "X" && button7.Text == "X" || * button2.Text == "X" && button5.Text == "X" && button8.Text == "X" || * button3.Text == "X" && button6.Text == "X" && button9.Text == "X" || * button1.Text == "X" && button5.Text == "X" && button9.Text == "X" || * button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))*/) { MessageBox.Show("ничья"); } }
private void AITimer_Tick(object sender, EventArgs e) { if (buttons.Count > 0) { int index = rand.Next(buttons.Count); buttons[index].Enabled = false; curretPlayer = Player.O; buttons[index].Text = curretPlayer.ToString(); buttons.RemoveAt(index); Check(); AITimer.Stop(); } }
private void playAI(object sender, EventArgs e) { foreach (Control x in this.Controls) { if (x is Button && x.Text == "?" && x.Enabled) { x.Enabled = false; currentPlayer = Player.O; x.Text = currentPlayer.ToString(); x.BackColor = System.Drawing.Color.LightGoldenrodYellow; AITimer.Stop(); Check(); break; } else { AITimer.Stop(); } } }