예제 #1
0
파일: Form1.cs 프로젝트: Aluvspam/Summer19
 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" && 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")
     {
         ComputerMoves.Stop();                        //opreste timer-ul
         MessageBox.Show("Player Wins!");             //afiseaza un mesaj
         playerWins++;                                //incrementeaza nr de victorii
         label1.Text = "Player Wins - " + playerWins; //update player 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")
     {
         ComputerMoves.Stop();                            //opreste timer-ul
         MessageBox.Show("Computer Wins!");               //afiseaza un mesaj
         computerWins++;                                  //incrementeaza nr de victorii
         label2.Text = "Computer Wins - " + computerWins; //update computer label
         ResetGame();
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: Aluvspam/Summer19
 private void ComputerMove(object sender, EventArgs e)
 {
     if (buttons.Count > 0)
     {
         int index = random.Next(buttons.Count);                     //genereaza un nr random din nr de butoane
         buttons[index].Enabled   = false;                           //asigneaza nr butonului
         currentPlayer            = Player.O;                        //seteaza computerul cu O
         buttons[index].Text      = currentPlayer.ToString();        //scrie O pe buton
         buttons[index].BackColor = System.Drawing.Color.DarkSalmon; //schimba culoarea butonului dupa ce a fost apasat
         buttons.RemoveAt(index);                                    //elimina butonul din lista
         Check();                                                    //verifica daca computerul a castigat ceva
         ComputerMoves.Stop();                                       //opreste timer-ul computerului
     }
 }