How do I automate my robot
I have a robot that is being controlled by key presses, if the key pressed equals a certain key, either up, down, left or right are registered and the robot will move. I also have the following methods to play around with:
- int getSpeed();
- void forwardGear();
- void reverseGear();
isTouchingWall(); Booleon
I basically want to say if speed equals 0 than I can shift up a gear and then accelerate.
And if the robot isTouchingWall() turn around or something.
I’m not sure how I can use the reverseGear() method yet.
This is my code so far:
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case 37:
super.turnLeft();
break;
case 38:
super.accelerate();
break;
case 39:
super.turnRight();
break;
case 40:
super.decelerate();
break;
}
}
You can use another Key for reverseGear() for example ‘r’