/
Dragon925
/
Python-Graphics
Обзор
Документация
Войти
/
Dragon925
/
Python-Graphics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
lesson_31
edit_obstacles.py
34 строки
1 KB
Alexandr Romanov
Пример выполнения задания 8
24 апр 2025, 19:38
24 апр 2025, 19:38
791e71d
Код
Авторство
О чём код?
from classes import Obstacle from random import choice, randint def check_new_obstacles(current_obstacles: list[Obstacle], obstacles: list[Obstacle], width: int): if current_obstacles: current_obstacles = add_obstacle_to_not_empty_list( current_obstacles, obstacles,width ) else: current_obstacles = add_obstacle_to_empty_list(obstacles, width) return current_obstacles def add_obstacle_to_not_empty_list(current_obstacles: list[Obstacle], obstacles: list[Obstacle], width: int) -> list[Obstacle]: last_obstacle = current_obstacles[-1] if width - last_obstacle.rect.right > 400 and len(obstacles) > len(current_obstacles): free_obstacles = list(set(obstacles) - set(current_obstacles)) new_obstacles = choice(free_obstacles) new_obstacles.rect.left = randint(width, width + 100) current_obstacles.append(new_obstacles) return current_obstacles def add_obstacle_to_empty_list(obstacles: list[Obstacle], width: int) -> list[Obstacle]: new_obstacle = choice(obstacles) new_obstacle.rect.left = randint(width, width + 100) return [new_obstacle] def delete_first_obstacle(current_obstacles: list[Obstacle]): if current_obstacles and current_obstacles[0].rect.right < 0: current_obstacles.pop(0) return current_obstacles