猫史档案馆


【Python作品分享】coco

用户:AngelaPeffiroAngelaPeffiro查看:0 回复:1 评论:0 创建时间:2020-12-12T19:25:05


【作品展示】

center_image

 

【作品介绍】

hhhhhhhhhhhhhhhhhhhh

 

【作品源代码】

import pgzrun

# 设置屏幕大小

# 初始分数
score = 
# 创建按钮角色,设置角色位置

# 剩余时间
time_left = 
# 游戏状态
game_over = 


def draw():
    # 填充浅蓝色的背景
    screen.fill("lightblue")
    # 显示按钮
    button.draw()
    # 显示分数
    screen.draw.text("Score: " + str(score), color="white",
                     center=(WIDTH / 2, 90), fontsize=50)
    # 显示倒计时
    screen.draw.text("Time Left: " + str(time_left),
                     color="white", center=(WIDTH / 2, 40),
                     fontsize=50)
    # 游戏结束后显示最终得分
    if game_over:
        screen.fill("lightblue")
        screen.draw.text("Final Score: " + str(score),
                         center=(WIDTH / 2, 150), fontsize=50)


# 点击按钮,得分增加
def on_mouse_down(pos):
    global score
    if not game_over:  # 如果游戏没有结束
        if button.collidepoint(pos):
            button.image = "button1_off"
            score += 1


# 松开鼠标按钮复原
def on_mouse_up():
    button.image = "button1_on"


# 倒计时
def update_time_left():
    global time_left, game_over
    if score > 0:
        if time_left > 0:
            time_left -= 1
        else:
            game_over = True

# 每隔 1 秒调用一次倒计时函数
clock.schedule_interval(update_time_left, 1.0)

pgzrun.go()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
code猫的code猫的

与coco有什么关系

点赞0


评论