猫史档案馆


【Python作品分享】Rapid click

用户:JimH6JimH6查看:0 回复:1 评论:0 创建时间:2020-05-14T17:29:32


【作品展示】

center_image

 

【作品介绍】

去点击zerogame里面的按钮,如果你点的模式是‘双人’,黄色的用s控制点击,绿色的用l控制点击。

尽量在7.5秒中让点击的次数最高!

 

【作品源代码】

import easygui,time,pgzrun
from random import *

choice = easygui.buttonbox('请选择一个模式。','choice',['单人:1','单人:2','双人'])
try:
    if choice == '单人:1':
        WIDTH = 310
        HEIGHT = 450
        score = 0
        time_left = 7.5
        game_over = False

        def tl():
            global time_left,game_over
            if score>0:
                if time_left > 0:
                    time_left -= 0.5
                else:
                    game_over = True

        button = Actor('button1_on')
        button.pos = WIDTH / 2,HEIGHT / 2 + 60
        def draw():
            screen.fill('lightblue')
            button.draw()
            screen.draw.text('Times:' + str(score),color = 'red',
                            center = (WIDTH / 2,90),fontsize = 50)
            screen.draw.text("Time left:" + str(time_left),color = "white",
                            center=(WIDTH / 2,45),fontsize = 45) 

            if game_over:
                screen.fill('lightblue')
                screen.draw.text("times UP!:",color = "purple",
                    center=(WIDTH / 2,90),fontsize = 55)
                screen.draw.text("final score:" + str(score), color="white",
                    center=(WIDTH / 2,150),fontsize = 50)
                    
        def on_mouse_up():
            button.image = 'button1_on'
        def on_mouse_down(pos):
            global score
            if button.collidepoint(pos):
                button.image = "button1_off"
                score += 1 
        clock.schedule_interval(tl,0.5)

        pgzrun.go()
    elif choice == '单人:2':
        WIDTH = 喵0
        HEIGHT = 480
        score = 0
        time_left = 7.5
        game_over = False

        def tl():
            global time_left,game_over
            if score>0:
                if time_left > 0:
                    time_left -= 0.5
                else:
                    game_over = True

        button = Actor('button1_on')
        button.pos = randint(60,WIDTH - 60),randint(60,HEIGHT - 60)
        def draw():
            screen.fill('lightblue')
            button.draw()
            screen.draw.text('Times:' + str(score),color = 'red',
                            center = (WIDTH / 2,90),fontsize = 50)
            screen.draw.text("Time left:" + str(time_left),color = "white",
                            center=(WIDTH / 2,45),fontsize = 45) 

            if game_over:
                screen.fill('lightblue')
                screen.draw.text("times UP!:",color = "purple",
                    center=(WIDTH / 2,90),fontsize = 55)
                screen.draw.text("final score:" +str(score),color = "white",
                    center=(WIDTH / 2,150),fontsize = 50)
        def on_mouse_up():
            button.image = 'button1_on'
            button.pos = randint(60, WIDTH - 60), randint(60, HEIGHT - 180)

        def on_mouse_down(pos):
            global score
            if button.collidepoint(pos):
                button.image = "button1_off"
                score += 1 
        clock.schedule_interval(tl,0.5)

        pgzrun.go()

    elif choice == '双人':
        WIDTH = 喵0
        HEIGHT = 480
        score = 0
        time_left = 7.5
        game_over = False

        def tl():
            global time_left,game_over
            if score>0:
                if time_left > 0:
                    time_left -= 0.5
                else:
                    game_over = True

        button = Actor('button1_on')
        button.pos = WIDTH / 2,HEIGHT / 2 + 60
        def draw():
            screen.fill('lightblue')
            button.draw()
            screen.draw.text('Times:' + str(score),color = 'red',
                            center = (WIDTH / 2,90),fontsize = 50)
            screen.draw.text("Time left:" + str(time_left),color = "white",
                            center=(WIDTH / 2,45),fontsize = 45) 

            if game_over:
                screen.fill('lightblue')
                screen.draw.text("times UP!:",color = "purple",
                    center=(WIDTH / 2,90),fontsize = 55)
                screen.draw.text("final score:" + str(score), color="white",
                    center=(WIDTH / 2,150),fontsize = 50)
                    
        def on_mouse_up():
            button.image = 'button1_on'
        def on_mouse_down(pos):
            global score
            if button.collidepoint(pos):
                button.image = "button1_off"
                score += 1 
        clock.schedule_interval(tl,0.5)

        pgzrun.go()
    easygui.msgbox('Game over.')
except:
    easygui.msgbox('点击错误,请重新点击.','msg')

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕咕

沙发

点赞0


评论