100-Days-Of-Code/Visual Studio Code Projects/turtle-crossing-start/car_manager.py
Arcron ArchLinux 4d3a07e207 Fixed Error
2024-10-29 18:08:45 +05:30

32 lines
850 B
Python

from turtle import Turtle
import random
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
class CarManager:
def __init__(self):
self.all_cars = []
self.car_speed = STARTING_MOVE_DISTANCE
def create_car(self):
random_chance = random.randint(1, 6)
if random_chance == 1:
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(-400, 400)
new_car.goto(1000, random_y)
self.all_cars.append(new_car)
def move_cars(self):
for car in self.all_cars:
car.backward(self.car_speed)
def level_up(self):
self.car_speed += MOVE_INCREMENT