Java - creating text adventure with no objects at all, -


this first time here, new programming, have been learning java 2 weeks , know basics, decided test knowledge doing simple text adventure game without using objects haven't got grip of yet. keep printing story , describing situation, , accepting player choices go on. having problem code don't know how repeat question if user entered invalid choice, tried couple of ways program either ends or gives me infinite loop, need ,please.

here code:

import java.util.scanner;  class the_crime {      public static void main(string[] args) {         scanner input = new scanner(system.in);         system.out.println("welcome stranger, please enter name");         string name = input.nextline();         system.out.println("welcome" + name);                street street = new street();          system.out.println("you in street dead body on floor drowned in blood \n there building right ahead of you\n do?");         string choice = input.nextline();         while(true) {             if(choice.equals("enter building")) {                 system.out.println("you have entered empty building");                  } else {                 system.out.println("you in street dead body lying around drawned in blood \n there building right infront of you\n do?");             }         }         }    } 

your while condition continue forever because never break out of it. not need in case change

while(true)      if (choice.equals("enter building"))           system.out.println("you have entered empty building");       else            system.out.println("you in street dead body lying around drawned in blood \n there building right infront of you\n do?"); 

to

while(choice.equals("some invalid choice")) {     choice = input.nextline(); } 

or

while(!choice.equals("some valid choice")) {     choice = input.nextline(); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -