-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car.py
58 lines (48 loc) · 1.27 KB
/
Car.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'''
IMPORTS
'''
import itertools
import random as rand
import math
import matplotlib.pyplot as plt
import numpy as np
import copy
'''
CAR CLASS
'''
class Car:
id_generator = itertools.count(1)
def __init__(self, car_type):
self.car_type = car_type
self.id = self.car_type + "_" + str(next(self.id_generator))
self.x = -5
self.speed_lim = 6
def set_speed(self, speed):
self.speed = speed
def incr_speed(self):
if self.speed < self.speed_lim:
self.speed += 1
def decr_speed(self):
if self.speed > 0:
self.speed -= 1
def brake(self):
self.speed = math.floor(self.speed / 2)
def drive(self):
self.x = math.floor(self.x + self.speed)
'''
SUBCLASSES OF CAR
'''
class Truck(Car):
def __init__(self):
super().__init__('truck')
self.speed_lim = 5
class Sedan(Car):
def __init__(self):
super().__init__('sedan')
class SUV(Car):
def __init__(self):
super().__init__('suv')
class Sport(Car):
def __init__(self):
super().__init__('sport')
self.speed_lim = 7