Beispiel #1
0
 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();
     }
 }
        public void FindingCorrectFreeSpace()
        {
            var board = new Board();

            board.AddMove(Tuple.Create(2, 2));
            board.AddMove(Tuple.Create(1, 1));
            var compTurn  = new ComputerMoves();
            var freeSpace = ComputerMoves.FindAvailableSpace(board);

            Assert.Equal(Tuple.Create(1, 2), freeSpace);
        }
Beispiel #3
0
        private void PlayerClick(object sender, EventArgs e) //metoda Event a player-ului (Click pe buton)
        {
            var button = (Button)sender;                     //afla ce buton s-a apasat

            currentPlayer    = Player.X;                     //seteaza playerul cu X
            button.Text      = currentPlayer.ToString();     //schimba textul de pe buton cu X
            button.Enabled   = false;                        //dezactiveaza butonul dupa ce s-a apasat
            button.BackColor = System.Drawing.Color.Cyan;    //schimba culoarea butonului apasat
            buttons.Remove(button);                          /*sterge butonul din lista de butoane pentru ca urmatorul
                                                              * player sa nu il poata apasa din nou*/
            Check();                                         //verifica daca playerul a castigat
            ComputerMoves.Start();                           //porneste Timer-ul pentru Computer (player2)
        }
Beispiel #4
0
 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
     }
 }