I've been working on a text based game for class and have been able to get most of it working with a little trial and error. But I've run into a roadblock with the user input parsing, which I've already had to simplify more than I like. The idea is to have a method that takes a string as the input, then calls a method in an object that was instantiated in another class. Here is the code, and yes, I know it's a convoluted mess.
It seems that I phrased this question a bit badly. I haven't actually encountered any problem beyond simply having no idea how to do what I want to. The approach suggested by Gilbert La Blanc was very good though, and has solved my problem. Maybe I actually will pass this final! Thank you all for your help.
import java.util.Scanner;
public class Parser{
static String[] Prepositions = {"on", "in", "under"};
static String Word;
public static void Parse(String Raw){
Raw.toLowerCase(); //Make input lower case
Scanner Splitter = new Scanner(Raw).useDelimiter(" "); //Split into seperate words
Word = Splitter.next(); //Get first word
Splitter.close();
CheckFirst(Word);
}
public static void CheckFirst(String Word){
switch(Word){
case "north":
case "n":
case "south":
case "s":
case "east":
case "e":
case "west":
case "w":
Player.Location.LeaveRoom(Word);
break;
case "take": TakeWhat(); break;
default: System.out.print("That was absolute gibberish!"); break;
}
}
public static void TakeWhat(){
System.out.println("Take what?");
System.out.print("> ");
String ToTake = Game.Input.next();
ToTake.toLowerCase();
switch(ToTake){
case "key": break;
default: TakeWhat();
}
}
}