猫史档案馆


【Python作品分享】click

用户:糖果PB糖果PB查看:0 回复:0 评论:0 创建时间:2022-08-23T22:06:30


【作品展示】

center_image

 

【作品介绍】

一起来拼手速吧!

 

【作品源代码】

import pgzrun

WIDTH = 640
HEIGHT = 480
score1 = 0
score2 = 0
button1 = Actor('botton1-1')
button1.pos = WIDTH / 4,HEIGHT / 2 + 60
button2 = Actor('botton2-1')
button2.pos = WIDTH - WIDTH / 4,HEIGHT / 2 + 60
time_left = 10
game_over = False


def draw():
    screen.fill('lightblue')
    button1.draw()
    button2.draw()
    screen.draw.text('press S:' + str(score1), color='white',center=(WIDTH / 4,150),fontsize=50)
    screen.draw.text('press L:' + str(score2), color='white',center=(WIDTH - WIDTH / 4, 150), 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('player S:' + str(score1), color='white',center=(WIDTH / 4, 120), fontsize=50)
        screen.draw.text('player L:' + str(score2), color='white',center=(WIDTH - WIDTH / 4, 120), fontsize=50)
        cup = Actor('cup')
        if score1 > score2:
            winner = 'The winner is player S!'
            cup.pos = WIDTH / 4,HEIGHT / 2

        elif score1 < score2:
            winner = 'The winner is player L!'
            cup.pos = WIDTH - WIDTH / 4, HEIGHT / 2

        else:
            winner = "It's a tie!"
            cup.pos = WIDTH / 2, HEIGHT / 2
        screen.draw.text(winner, color='white',center=(WIDTH / 2, 40), fontsize=50)
        cup.draw()

def on_key_down(key):
    global score1,score2
    if not game_over:
        if key == keys.S:
            button1.image = 'botton1-2'
            score1 += 1
        if key == keys.L:
            button2.image = 'botton2-2'
            score2 += 1

def on_key_up(key):
    if key == keys.S:
        button1.image = 'botton1-1'
    if key == keys.L:
        button2.image = 'botton2-1'


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)
pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页