Java text game parser problems -
this first post, , i'm new java, sorry if not scratch.
i have been writing text-based adventure game in java, , code has failed me in 1 place - parser. there no error, doesnt work. takes in input nil it. simple, , looks this:
public static void getinput(){ system.out.print(">>"); //print cue input string = scan.nextline(); //get (i)nput string[] w = i.split(" "); //split input (w)ords list words = arrays.aslist(w); //change list format test(words); }
the test method searches list words using if(words.contains("<word>"))
.
what wrong code , how can improve it?
how keeping array , using this:
string[] word_list = {"this","is","an","array"}; //an array in fault 'w' (int = 0;i < word_list.length;i++) { //running trough elements system.out.println(word_list[i]); if (word_list[i].equalsignorecase("this")) { system.out.println("this found!"); } if (word_list[i].equalsignorecase("is")) { system.out.println("is found!"); } if (word_list[i].equalsignorecase("an")) { system.out.println("an found!"); } if (word_list[i].equalsignorecase("array")) { system.out.println("array found!"); } if (word_list[i].equalsignorecase("notexistant")) { //wont found system.out.println("notexistant found!"); } }
you next output:
this found! found! found! array found!
as see need'nt convert list
java text adventure
No comments:
Post a Comment