SHARE
TWEET

Untitled

a guest Nov 13th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void createApples(int max) {
  2.     int loop = 0;
  3.     int appleX;
  4.     int appleY;
  5.     Element apple;
  6.     boolean exists;
  7.     int index;
  8.  
  9.     for (loop = 0; loop < max; loop++) {
  10.       exists = false;
  11.  
  12.       do {
  13.         appleX =
  14.             new Random().nextInt(bounds.width / SNAKE_SIZE) *
  15.             SNAKE_SIZE + SNAKE_SIZE / 2;
  16.         appleY =
  17.             new Random().nextInt(bounds.height / SNAKE_SIZE) *
  18.             SNAKE_SIZE + SNAKE_SIZE / 2;
  19.  
  20.         index = 0;
  21.         while (index < apples.size() && !exists) {
  22.           exists = apples.get(index).equal(appleX, appleY);
  23.           index++;
  24.         }
  25.  
  26.         if (!exists)
  27.           exists = player.contains(appleX, appleY);
  28.  
  29.         else if(mode == MODE_HOTSEAT)
  30.  
  31.         if (!exists)
  32.             exists = player.contains(appleX, appleY);
  33.  
  34.         if (!exists)
  35.           exists = player2.contains(appleX, appleY);
  36.       }
  37.       while (exists);
  38.  
  39.       apple = new Element(appleX, appleY, SNAKE_SIZE, Color.white, bounds);
  40.       apples.add(apple);
  41.     }
  42.   }
  43. //This is the section where i made the apples respawable aso.. i quess the problem should be somewhere here. Also, shoud i post the hole export for you?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top