Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get User Input to move the car
- public void getInput() {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- try {
- userInput = br.readLine();
- } catch(IOException ioe) {
- }
- if(userInput.equals("g") || userInput.equals("G")) {
- // Remove the Car from the Grid so a new one can be placed on the next Grid Redraw
- this.removeCar();
- carXPosition--;
- this.moveGrid();
- // Collsion Detection for the Left Side of the Track
- if(carXPosition <= super.trackLeft) {
- this.carFail();
- }
- }
- else if(userInput.equals("h") || userInput.equals("H")) {
- this.removeCar();
- carXPosition++;
- this.moveGrid();
- // Collision Detection for the Right side of the Track
- if(carXPosition >= super.trackRight) {
- this.carFail();
- }
- }
- else {
- this.removeCar();
- System.out.println("You Have Pressed the Wrong Key, use either g to move left or h to move right");
- }
- }
Add Comment
Please, Sign In to add comment