Make the taxi move.
Now that you have a good understanding of Object Oriented programming we will give you a challenge. You are provided with classes that you should use to make a little minibus taxi move. The taxi should not be able to move forward if the TrafficLight closest to it is red. When the taxi reaches the end of the road it should wrap around to the start of the road. If the up or down arrow is pressed the TrafficLight closest to the taxi should toggle between green, orange, and red. The taxi should be able to move forward if the light is green.
See the taxi here. It can’t move yet!
Find the code here
You are provided with classes which you should use to make the taxi move. Here are details of each class and it’s members functions.
Taxi class:
forward
- move taxi forwardreverse
- move taxi backwardsclosestTrafficLight
- get the TrafficLight closest to the current location of the taxi
TrafficLight class:
makeRed
- make the traffic light redmakeOrange
- make the traffic light orangemakeGreen
- make the traffic light greencurrentColor
- get the current color of the traffic lightis
- check if the color isred
,orange
orred
Keypress class:
Each function takes a function that is called when the corresponding key is pressed.
forward
- when the right arrow key is pressedreverse
- when the left arrow key is pressedup
- when the up arrow key is presseddown
- when the down arrow key is pressed
Write your code in index.js