/** The user input encapsulation for the project. At the time, you can set the desired heading of the rovers to any direction and cause an early shutdown. */ public class Shell implements Runnable { private Prodigy prodigy; private boolean quit = false; public Shell (Prodigy prodigy) { this.prodigy = prodigy; } public void run () { while (!quit && !prodigy.mapped()) { try { int available = System.in.available(); if (available == 0) continue; byte[] bytes = new byte[available]; System.in.read(bytes); String command = new String(bytes).trim(); if (command.equals("bye")) { System.out.println("Shutting down..."); prodigy.readings = 2000000; quit = true; } if (command.indexOf("head") != -1) { String heading = command.replaceAll("head ",""); int degrees = new Integer(heading).intValue(); System.out.println("Setting new heading to "+degrees); Rover.setDesiredHeading(degrees); } else { System.out.println("Unknown command - "+command); } } catch (java.io.IOException ioe) {} } } }