-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcar_manager.py
More file actions
27 lines (25 loc) · 799 Bytes
/
car_manager.py
File metadata and controls
27 lines (25 loc) · 799 Bytes
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
from turtle import Turtle
import random
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARTING_MOVE_DISTANCE = 4
MOVE_INCREMENT = 5
class CarManager:
def __init__(self):
self.all_cars = []
self.speed=STARTING_MOVE_DISTANCE
def create_car(self):
cool=random.randint(1,7)
if cool==1:
tim=Turtle()
tim.penup()
tim.shape("square")
tim.shapesize(stretch_wid=1,stretch_len=2)
tim.color(random.choice(COLORS))
tim.goto(300,random.randint(-250,250))
tim.setheading(180)
self.all_cars.append(tim)
def move_all(self):
for _ in self.all_cars:
_.forward(self.speed)
def increase_speed(self):
self.speed+=MOVE_INCREMENT