private void Check() { if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X" || button4.Text == "X" && button5.Text == "X" && button6.Text == "X" || button7.Text == "X" && button8.Text == "X" && button9.Text == "X" || button1.Text == "X" && button5.Text == "X" && button9.Text == "X" || button3.Text == "X" && button5.Text == "X" && button7.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") { Almoves.Stop(); MessageBox.Show("player wins"); //playerWins++; resetGame(); } else if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O" || button4.Text == "O" && button5.Text == "O" && button6.Text == "O" || button7.Text == "O" && button8.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 == "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") { Almoves.Stop(); MessageBox.Show("computer wins"); computerWins++; resetGame(); } }
private void Almove(object sender, EventArgs e) { if (buttons.Count > 0) { int index = rnd.Next(buttons.Count); buttons[index].Enabled = false; currentPlayer = Player.O; //progressBar1.ForeColor= Color.DarkBlue; buttons[index].Text = currentPlayer.ToString(); buttons[index].BackColor = System.Drawing.Color.DarkBlue; buttons.RemoveAt(index); Check(); Almoves.Stop(); } }
private void playerClick(object sender, EventArgs e) { var button = (Button)sender; currentPlayer = Player.X; //progressBar1.ForeColor = Color.Red; button.Text = currentPlayer.ToString(); button.Text = currentPlayer.ToString(); button.Enabled = false; button.BackColor = System.Drawing.Color.Red; buttons.Remove(button); Check(); Almoves.Start(); }