def draw_game_over(): global USERNAME, mas img2048 = pygame.image.load('images.png') font = pygame.font.SysFont("stxingkai", 65) text_game_over = font.render("Game over! ", True, WHITE) text_score = font.render(f"Вы набрали {score}", True, WHITE) best_score = GAMERS_DB[0][1] if score > best_score: text = "Рекорд побит" else: text = f"Рекорд {best_score}" text_record = font.render(text, True, WHITE) insert_result(USERNAME, score) make_disicion = False while not make_disicion: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.type == pygame.K_SPACE: make_disicion = True init_const() elif event.type == pygame.K_RETURN: USERNAME = None make_disicion = True init_const() screen.fill(BLACK) screen.blit(text_game_over, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update() screen.fill(BLACK)
def draw_game_over(): global USERNAME, mas, score, GAMERS_DB img2048 = pygame.image.load('2048_logo.png') font = pygame.font.SysFont('comicsansms', 45) text_game_over = font.render('Game over! ', True, WHITE) text_score = font.render(f'Your score is {score} ', True, WHITE) best_score = GAMERS_DB[0][1] if score > best_score: text = 'New record!' else: text = f'Best score is {best_score}' text_record = font.render(text, True, WHITE) insert_result(USERNAME, score) GAMERS_DB = get_best() make_decision = False while not make_decision: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: make_decision = True init_const() elif event.type == pygame.K_RETURN: USERNAME = None make_decision = True init_const() screen.fill(BLACK) screen.blit(text_game_over, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update() screen.fill(BLACK)
def draw_game_over(): global USERNAME screen.fill(BLACK) # закрасим все что есть черным try: # мало ли, вдруг картинки не будет img_logo = pygame.image.load('gameover.jpg') # логотип screen.blit( pygame.transform.scale(img_logo, [SIZE_BLOCK * 2, SIZE_BLOCK * 2]), [MARGIN, MARGIN]) # размер картинки except: pass screen.blit(TEXT_GAME_OVER, (SIZE_BLOCK * 2 + MARGIN * 2, MARGIN * 8)) if GAMERS_DB: best_score = GAMERS_DB[0][1] else: best_score = 0 # БД пустая if score > best_score: # был поставлен рекорд text = "Record broken!" else: text = f"Record {best_score}" text_score = FONT_NAME.render(f"Your score {score}", True, COLOR_TEXT) screen.blit(text_score, (MARGIN * 3, HEIGTH // 2)) text_record = FONT_NAME.render(text, True, COLOR_TEXT) screen.blit(text_record, (MARGIN * 3, HEIGTH // 2 + SIZE_BLOCK // 2)) # пробел - еще раз, enter - новая игра text_space = FONT_SCORE.render("<Space> try again", True, COLOR_TEXT) text_enter = FONT_SCORE.render("<Enter> new gamer", True, COLOR_TEXT) screen.blit(text_space, (MARGIN * 3, HEIGTH - MARGIN * 9)) screen.blit(text_enter, (MARGIN * 3, HEIGTH - MARGIN * 5)) pygame.display.update() # обновим изменения графики insert_result(USERNAME, score) # запишем результат в БД make_disicion = False # приняли решение в конце игры? while not make_disicion: for event in pygame.event.get( ): # опрос событий (нажатие кнопок и т.п.) if event.type == pygame.QUIT: # нажали на крестик "x" pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: # любая другая кнопка if event.key == pygame.K_RETURN: # Enter # перезапускаем игру с новым игроком USERNAME = None make_disicion = True elif event.key == pygame.K_SPACE: # пробел # перезапускаем игру с этим же именем make_disicion = True screen.fill(BLACK) # закрасим все что есть черным
def draw_game_over(): global USERNAME, mas, score, GAMERS_DB img2048 = pygame.image.load('IMG2048.png') font = pygame.font.SysFont("comicsansms", 50) text_game_over = font.render("Game over!", True, WHITE) text_score = font.render(f"Your score {score} ", True, WHITE) best_score = GAMERS_DB[0][1] if score > best_score: text = "New record" else: text = f"Record {best_score}" text_record = font.render(text, True, WHITE) insert_result(USERNAME, score) GAMERS_DB = get_best() make_disicion = False while not make_disicion: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: make_disicion = True init_const() # restart with name elif event.key == pygame.K_RETURN: # restart without name USERNAME = None make_disicion = True init_const() screen.fill(BLACK) screen.blit(text_game_over, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update() screen.fill(BLACK)
def draw_game_over(): # функция завершающей заставки global USERNAME, mas, score, GAMERS_DB img2048 = pygame.image.load('og_image.png') font = pygame.font.SysFont("comicsansms", 50) text_game_over = font.render("Game over!", True, WHITE) text_score = font.render(f"Вы набрали {score}", True, WHITE) best_score = GAMERS_DB[0][1] if score > best_score: # условие, побит ли рекорд? text = "Рекорд побит" else: text = f"Рекорд {best_score}" text_record = font.render(text, True, WHITE) insert_result(USERNAME, score) GAMERS_DB = get_best() make_disicion = False while not make_disicion: # бесконечный цикл, в котором обрабатываются события for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: # restart game with name make_disicion = True init_const() elif event.key == pygame.K_RETURN: # restart gamr without name USERNAME = None make_disicion = True init_const() screen.fill(BLACK) screen.blit(text_game_over, (220, 85)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update() screen.fill(BLACK)
def draw_game_over(): global USERNAME, mas, score, GAMERS_DB img2048 = pygame.image.load('image.png') font = pygame.font.SysFont('comicsansms', 45) text_game_over = font.render('Game over!', True, white) text_score = font.render(f'Вы набрали {score}', True, white) best_score = GAMERS_DB[0][1] if score > best_score: text = 'Рекорд побит' else: text = f'Рекорд {best_score}' text_record = font.render(text, True, white) insert_result(USERNAME, score) GAMERS_DB = get_best() make_decision = False while not make_decision: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: # restart game with name make_decision = True init_const() elif event.key == pygame.K_RETURN: # restart game without name USERNAME = None make_decision = True init_const() screen.fill(black) screen.blit(text_game_over, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 320)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update() screen.fill(black)
def draw_game_over(): global USERNAME, mas, score, GAMERS_DB img = pygame.image.load("2048_logo.svg.png") font_game_end = pygame.font.SysFont("simsum", 70) text_game_end = font_game_end.render("The end", True, WHITE) text_score = font_game_end.render('Your score is: {0}'.format(score), True, WHITE) best_score = GAMERS_DB[0][1] if score > best_score: text = "YOU WIN" else: text = 'Record {0}'.format(best_score) text_record = font_game_end.render(text, True, WHITE) insert_result(USERNAME, score) GAMERS_DB = get_best() make_desigion = False while not make_desigion: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: # restart with name make_desigion = True init_const() elif event.key == pygame.K_RETURN: # restart new gamer USERNAME = None make_desigion = True init_const() screen.fill(BLACK) screen.blit(text_game_end, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img, [200, 200]), [10, 10]) pygame.display.update() screen.fill(BLACK)
def draw_game_over(): img2048 = pygame.image.load('2048intro.jpg') font = pygame.font.SysFont("simsun", 60) text_game_over = font.render("Game over!", True, WHITE_MINT) text_score = font.render(f"Вы набрали {score}", True, WHITE_MINT) best_score = GAMERS_DB[0][1] if score > best_score: text = 'НОВЫЙ РЕКОРД!' else: text = f'Рекорд {best_score}' text_record = font.render(text, True, WHITE_MINT) insert_result(USERNAME, score) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) screen.fill(BLACK) screen.blit(text_game_over, (220, 80)) screen.blit(text_score, (30, 250)) screen.blit(text_record, (30, 300)) screen.blit(pygame.transform.scale(img2048, [200, 200]), [10, 10]) pygame.display.update()
def draw_gameover(): """зарисовка заключителььного экрана""" global USERNAME, GAMERS_DB, field img = pygame.image.load('2048.png') font_gameover = pygame.font.SysFont('Times New Roman', 50) font_help = pygame.font.SysFont('Arial', 20) text_help_space = 'Press SPACE to restart game with old name' text_help_enter = 'Press ENTER to restart game without old name' text_gameover = font_gameover.render('Game over!', True, INTERFACE_TEXT_COLOR) text_result_score = font_gameover.render(f'You have {score}', True, INTERFACE_TEXT_COLOR) text_help_space = font_help.render(f'{text_help_space}', True, INTERFACE_TEXT_COLOR) text_help_enter = font_help.render(f'{text_help_enter}', True, INTERFACE_TEXT_COLOR) best_score = GAMERS_DB[0][1] if score > best_score: text = 'You bit record!!!' else: text = f'Record is {best_score}' text_record = font_gameover.render(text, True, INTERFACE_TEXT_COLOR) insert_result(USERNAME, score) restart = False while not restart: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: # после окончания игры при нажатии на 'пробел' рестартим игру, # инициализируем данные и сохраняем старое имя insert_result(USERNAME, score) restart = True init_game() elif event.key == pygame.K_RETURN: # после окончания игры при нажатии на 'enter' рестартим игру, # инициализируем данные и обнуляем старое имя insert_result(USERNAME, score) USERNAME = None restart = True init_game() screen.fill(pygame.color.Color('orange')) screen.blit(text_gameover, (120, 250)) screen.blit(text_result_score, (100, 300)) screen.blit(text_record, (100, 350)) screen.blit(text_help_space, (30, 500)) screen.blit(text_help_enter, (30, 530)) screen.blit(pygame.transform.scale(img, (200, 200)), (140, 10)) pygame.display.update() screen.fill(pygame.color.Color('black'))