用户:一只诺如影查看:1 回复:4 评论:1 创建时间:2020-06-19T13:17:26
【作品展示】

【作品介绍】
天哪,我终于做出了它,这是我第一次做出超过30行代码的游戏,快来测一测你的手速吧!
【作品源代码】
import pgzrun
WIDTH = 310
HEIGHT = 450
score = 0
button = Actor("button1_on")
button.pos = WIDTH / 2,HEIGHT / 2 + 60
time_left = 5
game_over = False
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="red",center=(WIDTH / 2, 40),
fontsize=50)
if game_over:
screen.fill("cyan")
screen.draw.text("Final Scores: " + str(score),
center=(WIDTH / 2, 150), fontsize=50)
def on_mouse_down(pos):
global score
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
clock.schedule_interval(update_time_left,1.0)
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn