lundi 20 avril 2020

I can't understand why those value are different

I want to make Player1_Score and Player2_Score have different value. So I wrote like this.

  class player
{
    protected int Player1_Score;

    public int Player1_Score_Pick()
    {

        Random a = new Random();
        Player1_Score = a.Next(1, 101);
        return Player1_Score;



    }

}
    class player2:player
{
    protected int Player2_Score;
    public int Player2_Score_Pick()
    {
        Random a = new Random();
        Player2_Score = a.Next(1, 101);

        if (Player1_Score != Player2_Score)
        {

            Player2_Score = a.Next(1, 101);
        }

        return Player2_Score;



    }
     private void Strat_Click(object sender, EventArgs e)
    {

       Player1_Score.Text= player1.Player1_Score_Pick().ToString();
       Player2_Score.Text= player2.Player2_Score_Pick().ToString();
    }

In this case they have another value. But I can't understand why. At first try I wrote /if (Player1_Score == Player2_Score)/. But they have same value at this case. What is the problem???




Aucun commentaire:

Enregistrer un commentaire