-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_manager.py
32 lines (26 loc) · 935 Bytes
/
car_manager.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
from turtle import Turtle
import random
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
class CarManager(Turtle):
def __init__(self):
super().__init__()
self.all_cars = []
self.hideturtle()
self.car_speed = STARING_MOVE_DISTANCE
def create_cars(self):
random_chance = random.randint(1, 6)
if random_chance == 6:
new_car = Turtle("square")
new_car.shapesize(stretch_wid=1 ,stretch_len=2)
new_car.penup()
new_car.color(random.choice(COLORS))
random_y = random.randint(-250, 250)
new_car.goto(300, random_y)
self.all_cars.append(new_car)
def move_cars(self):
for car in self.all_cars:
car.back(self.car_speed)
def level_up(self):
self.car_speed += MOVE_INCREMENT