i trying make typing adventure kind of game in java, need command @ least similar 1 in title, here code
import java.util.scanner; public class myfirstgameinjava { public static void main(string[] args) { system.out.println("greetings, enter name , may start quest!"); scanner username = new scanner(system.in); string name = username.nextline(); system.out.println("greetings " + name ); system.out.println("welcome unnamed typing advanture"); system.out.println("you find on island few trees, can either hit tree, or walk along"); string sc = username.nextline(); switch(sc){ case "hit tree": system.out.println("a coconut falls tree"); system.out.println("you can either eat coconut or throw it"); break; case "walk": system.out.println("you walk mile , find village"); system.out.println("the village appears empty, can either scream see if there, or can keep walking"); break; default : system.out.println("nothing happens..."); } string sc1 = username.nextline(); switch(sc1){ case "eat coconut": system.out.println("you ate coconut , got poisoned"); system.out.println("you died..."); break; case "throw coconut": system.out.println("by throwing coconut, awaken tiger , eats you"); system.out.println("you dead"); break; case "scream": system.out.println("as scream, man shoots down window 1 of houses"); system.out.println("you died..."); break; case "walk": system.out.println("you walked through village, , find boat , leave island"); system.out.println("you win! updates coming soon!"); break; default: system.out.print("nothing happend"); } } }
whenever user types else required, default case happens, need go start of loop, user can type 1 of other cases.
you can use continue
statement continue next iteration.
that said, don't see loop in sample code. can loop for
, while
or do/while
. do/while loop executes @ least once -- typically want when asking user question.
this java tutorial branching statements provides example of continue
statement in for
loop.
(int = 0; < max; i++) { // interested in p's if (searchme.charat(i) != 'p') continue; // process p's numps++; }
Comments
Post a Comment