贪吃蛇

所属课程: 人工智能大变革(16星期,32课时)

*梓晨

12岁

发布于:15天前
浏览数:13

# 初始分数
score = 0

# 显示评分功能
def show_score(choice, color, font, size):
    # 创建字体对象 score_font
    score_font = pygame.font.SysFont(font, size)
    # 创建显示表面对象 score_surface
    score_surface = score_font.render('Score :' + str(score), True, color)
    # 为文本表面对象创建一个矩形对象
    score_rect = score_surface.get_rect()
    # 显示文字
    game_window.blit(score_surface, score_rect)

# 游戏结束功能
def game_over():
    # 创建字体对象 my_font
    my_font = pygame.font.SysFont('times new roman', 50)
    # 创建将在其上绘制文本的文本表面
    game_over_surface = my_font.render('Your Score is :' + str(score), True, red)
    # 为文本表面对象创建一个矩形对象
    game_over_rect = game_over_surface.get_rect()
    # 设置文本位置
    game_over_rect.midtop = (window_x / 2, window_y / 4)
    # blit 将在屏幕上绘制文本
    game_window.blit(game_over_surface, game_over_rect)
    pygame.display.flip()
    # 2 秒后我们将退出程序
    time.sleep(2)
    # 停用 pygame 库
    pygame.quit()
    # 退出程序
    quit()    

 

 

 

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!