Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // Get User Input to move the car
  2.  
  3. public void getInput() {
  4.  
  5. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  6.  
  7. try {
  8.  
  9. userInput = br.readLine();
  10.  
  11. } catch(IOException ioe) {
  12.  
  13. }
  14.  
  15. if(userInput.equals("g") || userInput.equals("G")) {
  16.  
  17. // Remove the Car from the Grid so a new one can be placed on the next Grid Redraw
  18. this.removeCar();
  19.  
  20. carXPosition--;
  21.  
  22. this.moveGrid();
  23.  
  24. // Collsion Detection for the Left Side of the Track
  25. if(carXPosition <= super.trackLeft) {
  26.  
  27. this.carFail();
  28. }
  29. }
  30.  
  31.  
  32. else if(userInput.equals("h") || userInput.equals("H")) {
  33.  
  34. this.removeCar();
  35. carXPosition++;
  36. this.moveGrid();
  37.  
  38. // Collision Detection for the Right side of the Track
  39.  
  40. if(carXPosition >= super.trackRight) {
  41.  
  42. this.carFail();
  43. }
  44. }
  45.  
  46. else {
  47. this.removeCar();
  48. System.out.println("You Have Pressed the Wrong Key, use either g to move left or h to move right");
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment