mercredi 29 avril 2015

Testing if random number equals a specific number

I know this might already have been answered, but all the places where i found it, it wouldn't work properly. I'm making a game in Greenfoot and I'm having an issue. So I'm generating a random number every time a counter reaches 600, and then testing if that randomly generated number is equal to 1, and if it is, it creates an object. For some reason, the object will be created every time the counter reaches 600. I'm somewhat new to Java so it's probably something simple.

if (Counter > 600)
  {
      int randomNumber = random.nextInt(10);

      if (randomNumber == 1)
      {          
          Invincible invincible = new Invincible();
          addObject(invincible, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()));
          Counter = 0;
      }
      else 
      {              
      }
    }
 Counter ++;
}

I'm not getting errors as it is compiling fine, but when i run it i have issues. Any help? Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire