java - Why does my Loop mechanism not work? -


sorry if closed question won't useful others, i'm stumped bug , haven't been able solve weeks!

i working on wave based survival game , working on spawning mechanism. code wrote works 1 wave, somehow doesn't restart further waves. have written code below:

public void run() {     while (ingame) {         if (enemylist.isempty()) {             stopspawn = false;             try {                 thread.sleep(500);                 spawnnewenemy();             } catch (interruptedexception ex) {                 system.out.println("interrupted");             }         } else {             if (!enemylist.isempty() && !stopspawn) {                 // getenemyamount returns amount of enemies should spawned wave                 (int enemiesspawned = 0; enemiesspawned < getenemyamount(); enemiesspawned++) {                     try {                         thread.sleep(500);                     } catch (interruptedexception ex) {                     }                     system.out.println(currentwave);                     spawnnewenemy();                 }                 stopspawn = true;             }         }     } } 

here spawnnewenemy method

 public void spawnnewenemy() {     random spawn = new random();     int spawnx = spawn.nextint(500);     int spawnxtest = b.bx - spawnx;     if (spawnxtest < 20) {         spawnx = spawnx + 20;     } else {     }     int spawny = spawn.nextint(500);     int spawnytest = b.bx - spawny;     if (spawnytest < 20) {         spawny = spawny + 20;     } else {     }     spawny = spawny + 20;     spawnx = spawnx + 20;     enemylist.add(new enemy(spawnx, spawny)); } 

i can read following in code:

  • if list of enemies empty, set stopspawn false , spawn enemy.
  • that triggers else-statement.
  • there, spawn enemies based on enemy count.
  • stopspawn set true, else-statement doesn't triggered anymore.
  • nothing happens anymore untill enemylist empty.
  • if enemylist empty again, start over.

the logics seems ok, i'm thinking either way spawn enemies through spawnnewenemy() faulty, or way remove enemies enemylist faulty. see neither of code far can go in answer.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -