猫史档案馆


【Python作品分享】作品2.4

用户:W莫斯科客MW莫斯科客M查看:0 回复:0 评论:0 创建时间:2022-08-10T15:35:37


【作品展示】

center_image

 

【作品介绍】

......................................................,.........................................................................自己看!

 

【作品源代码】

import pgzrun

WIDTH = 800
HEIGHT = 600
score1 = 0
score2 = 0
time_left = 5
game_over = False

button = Actor("button1_on")
button.pos = WIDTH / 4, HEIGHT / 2+60

button1 = Actor("button2_on")
button1.pos = WIDTH - WIDTH / 4, HEIGHT / 2+60

def on_key_down(key):
    global score1,score2
    if not game_over:
        if key == key.S:
            button.image = "button1_off"
            score1 += 1
        if key == key.K:
            button1.image = "button2_off"
            score2 += 1

def on_key_up(key):
    if key == key.S:
       button.image = "button1_on"
    if key == key.K:
       button1.image = "button2_on"

def draw():
    screen.fill("lightblue")
    button.draw()
    button1.draw()
    screen.draw.text("score1: " + str(score1), color="#ccffff",
                     center=(WIDTH / 4, 90), fontsize=50)
    screen.draw.text("score2: " + str(score2), color="#ccffff",
                     center=(WIDTH - WIDTH / 4, 90), fontsize=50)
    screen.draw.text("Time Left: " + str(time_left),
                     color="#ccffff", center=(WIDTH / 2, 40), fontsize=50)
                
    if game_over:
        screen.fill("lightblue")
        screen.draw.text("Final Score1: " + str(score1),
                        center=(WIDTH / 4, 90), fontsize=50)
        screen.draw.text("Final Score2: " + str(score2),
                         center=(WIDTH - WIDTH / 4, 90), fontsize=50)
        
        if score1 > score2:
            winner = "The winner is play 1!"
        elif score1 < score2:
            winner = "The winner is play 2!"
        else:
            winner = "It's a tie!!!!"

def update_time_left():
    global time_left, game_over
    if score1 > 0 or score2 > 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


回复

上一页1 页 / 共 0下一页