def __init__(self): pygame.init() config.screen = pygame.display.set_mode( (config.screen_width, config.screen_height)) config.screen.fill(colors.white) new_snake = Snake() config.snakes += [new_snake] place = Place() config.process = True while config.process: for i in pygame.event.get(): if i.type == pygame.QUIT: #ыыыыыыыыыыыыы exit() pressed = pygame.mouse.get_pressed() if pressed[0]: speeding = 2 else: speeding = 1 for s in config.snakes: s.move(speeding) while config.food_energy + config.snake_energy < config.max_energy: # Ну или сколько там new_food = Food() config.all_food += [new_food] config.screen.fill(colors.black) for f in config.all_food: f.draw(new_snake.coords) for s in config.snakes: s.draw() place.draw(new_snake.coords) pygame.display.update() pygame.time.delay(40)
def game(self): #после нажатия на кнопку play начинаем играть pygame.init() config.screen = pygame.display.set_mode( (config.screen_width, config.screen_height)) config.screen.fill(colors.white) new_snake = Snake() config.snakes += [new_snake] place = Place() config.process = True while config.process: for i in pygame.event.get(): if i.type == pygame.QUIT: exit() pressed = pygame.mouse.get_pressed() if pressed[0]: speeding = 2 else: speeding = 1 for s in config.snakes: s.move(speeding) while config.food_energy + config.snake_energy < config.max_energy: # Ну или сколько там new_food = Food() config.all_food += [new_food] config.screen.fill(colors.black) for f in config.all_food: f.draw(new_snake.coords) for s in config.snakes: s.draw() place.draw(new_snake.coords) pygame.display.update() pygame.time.delay(40) if new_snake.life == 0: if config.length < new_snake.length: #print(new_snake.length) config.length = new_snake.length new_game = Main()