View Single Post
  #2 (permalink)  
Old 08-07-2007, 07:28 AM
trill trill is offline
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
Why not put a character or space in between the command and parameter? That way you can utilize Java's Split function and do something like the below.

iTurtle.txt

Code:
U D N-13 S-10 E-3 W-9
Sample Java code

Code:
enum Commands {U, D, N, S, E, W}; String thought; while ((thought = turtleBrain.readLine()) != null){ String[] instructions = thought.split("-"); Commands com = instructions[0]; switch (com) { case U: Romina.setPenState("u"); break; case D: Romina.setPenState("d"); break; case N: Romina.moveNorth(instructions[1]); break; case S: Romina.moveSouth(instructions[1]); break; case E: Romina.moveEast(instructions[1]); break; case W: Romina.moveWest(instructions[1]); break; default: System.out.println("Invalid Command"); break; } }
Greetings.
Reply With Quote