A Simple Traffic Simulator

There are four types of cars on the road: trucks (gray), sedans (navy blue), SUVs (light blue) and sports (red). They follow simple rules as to when to speed up, slow down or break hard. They differ in their passenger capacity and maximum speed. Each car has a driver and a random number of passengers up to capacity. Those are marked as little squares. Each car displays its current speed in a bubble behind it. When it hits the breaks the bubble turns red. Before a car enters the road its plate, serial number and the identity of its driver and passengers are revealed.
This is an example of Object Oriented Programing with ES6. The driver and passengers are objects, instances of the Person class. Each car on the road is an object, an instance of the of a subclass, either Truck, Sport, Sedan or SUV that inherits from a Car class. A simulation object, instance of the Sim class, controls the cars on each road. At set intervals the Simulation is stepped forward. A visualization Object, instance of the Vis class generates and refreshes the UI for each road.
Made by Ron Ilan (2017)
0
0
0
0