예제 #1
0
 void move_button(string player, Button hold_button, Button move_button)
 {
     try
     {
         if (player == "Player-1")
         {
             if (hold_button.Text == "0")
             {
                 move_button.Text      = hold_button.Text;
                 hold_button.Text      = "";
                 move_button.ForeColor = Color.Blue;
                 record_condition("Player-1", move_button.Name, "Move to ");
                 check_back_color_button();
                 moves("0");
                 if (TicTacToeUtils.CheckAndProcessWinner(_buttonArray))
                 {
                     condition.Text = "Player 1 Won The Match";
                     MessageBox.Show("Game Over.. Player 1 won The Match");
                     disable();
                 }
             }
             else
             {
                 MessageBox.Show("Invalid Move..");
             }
         }
         else
         {
             if (hold_button.Text == "X")
             {
                 move_button.Text      = hold_button.Text;
                 hold_button.Text      = "";
                 move_button.ForeColor = Color.Red;
                 record_condition("Player-2", move_button.Name, "Move to ");
                 check_back_color_button();
                 moves("X");
                 if (TicTacToeUtils.CheckAndProcessWinner(_buttonArray))
                 {
                     condition.Text = "Player 2 Won The Match";
                     MessageBox.Show("Game Over.. Player 2 won The Match");
                     disable();
                 }
             }
             else
             {
                 MessageBox.Show("Invalid Move..");
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
예제 #2
0
 void Place_Point(Button button)
 {
     try
     {
         if (condition.Text.Split(new char[] { ' ' })[0].ToString() == "Player-1")
         {
             if (current_player1 == "")
             {
                 if ((p1 < 3) && (button.Text == ""))
                 {
                     button.Text      = "0";
                     button.ForeColor = Color.Blue;
                     record_condition("Player-1", button.Name, "Placed at ");
                     if (TicTacToeUtils.CheckAndProcessWinner(_buttonArray))
                     {
                         condition.Text = "Player 1 Won The Match";
                         MessageBox.Show("Game Over.. Player 1 won The Match");
                         disable();
                     }
                     p1++;
                     if (p1 <= 3)
                     {
                         conditions("0");
                     }
                     else
                     {
                         moves("0");
                     }
                 }
                 else
                 {
                     check_back_color_button();
                     possi_moves(Convert.ToInt32(button.Name.Substring(6)), "0", button);
                 }
             }
             else
             {
             }
         }
         else
         {
             if (current_player2 == "")
             {
                 if ((p2 < 3) && (button.Text == ""))
                 {
                     button.Text      = "X";
                     button.ForeColor = Color.Red;
                     record_condition("Player-2", button.Name, "Place at ");
                     if (TicTacToeUtils.CheckAndProcessWinner(_buttonArray))
                     {
                         condition.Text = "Player 2 Won The Match";
                         MessageBox.Show("Game Over.. Player 2 won The Match");
                         disable();
                     }
                     p2++;
                     if (p2 <= 2)
                     {
                         conditions("X");
                     }
                     else
                     {
                         moves("X");
                     }
                 }
                 else
                 {
                     check_back_color_button();
                     possi_moves(Convert.ToInt32(button.Name.Substring(6)), "X", button);
                 }
             }
             else
             {
             }
         }
     }
     catch (Exception ex)
     {
     }
 }