My java game isn't working -


so i'm still beginner managed code didn't work wanted, main problem every time press 1 resets enemy instead of keeping same one. appreciate if me. far have made writing 1 something.

package game;  import java.util.random; import java.util.scanner;  public class main {     public static void main(string[] args) {          scanner in = new scanner(system.in);         random r = new random();         system.out.println("welcome dragon heart");         system.out.println("1. start");         system.out.println("2. quit");          int input = 0, enemyhealth = 75, enemyattack = 15, playerhealth = 100, playerattack, random;         boolean enemydead = true, playerdead = false;         input = in.nextint();          if (input == 1) {             system.out.println("game started!");             while (0 != 1) {                 if (enemydead = true) {                     enemyhealth = r.nextint(50) + 51;                     enemyattack = r.nextint(15) + 6;                     system.out.println("an enemy appears, has " + enemyhealth + " health points , " + enemyattack + " attack points");                 } else {                     system.out.println("the enemy has " + enemyhealth + "health points");                 }                 system.out.println("1. attack");                 system.out.println("2. defend");                 system.out.println("3. run away");                 system.out.println("4. nothing");                 input = in.nextint();                 if (input == 1) {                     playerattack = r.nextint(5) + 21;                     random = r.nextint(2) + 1;                     enemyhealth = enemyhealth - playerattack;                     if (random == 1) {                         playerhealth = playerhealth - enemyattack;                     }                     if (enemyhealth <= 0) {                         enemydead = true;                         system.out.println("the enemy has been killed");                     } else {                         enemydead = false;                     }                 }              }          } else if (input == 2) {             system.out.println("game quit.");         }     } } 

your logic defense away dubious, problem here:

if(enemydead = true) 

you're reassigning enemydead true every single time.

you want check if enemy dead, accomplished this:

if(enemydead) 

further, clean while (0 != 1) while(true) instead. however, you're going need include break statement somewhere in loop it's not infinite loop now.

lastly, it's idea have lower-case package names opposed upper-case package names.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -