猫史档案馆


【Python作品分享】1.神奇衣帽间【作业帖】

用户:小河U小河U查看:9 回复:5 评论:9 创建时间:2020-08-26T21:44:11


【作品展示】

center_image

 

【作品介绍】

经过一天的学习,终于根据书上的做出来了!交作业!

 

【作品源代码】

import pgzrun
import random

WIDTH = 620
HEIGHT = 900

girl = Actor("co")
girl.pos = 300,550

hair_style = ["hair_1", "hair_2", "hair_3", "hair_4"]
hair = Actor("hair_1")
hair.pos = 317, 469

dress_style = ["dress_1", "dress_2", "dress_3", "dress_4"]
dress = Actor("dress_1")
dress.pos = 313,653

shoes_style = ["shoes_1","shoes_2","shoes_3","shoes_4"]
shoes = Actor("shoes_1")
shoes.pos = 312,780

button1 = Actor("rand")
button1.pos = 120,120

button2 = Actor("match")
button2.pos = 500,120

def draw():
    screen.blit("background",(0,0))
    girl.draw()
    hair.draw()
    dress.draw()
    shoes.draw()
    button1.draw()
    button2.draw()

def changestyle(obj,styleList):
    style = styleList.index(obj.image)
    if (style < 3):
        obj.image = styleList[style + 1]
    else:
        obj.image = styleList[0]
    
def change_all():
    suit = random.randint(0,3)
    dress.image = dress_style[suit]
    hair.image = hair_style[suit]
    shoes.image = shoes_style[suit]

def rand_change():
    dress.image = random.choice(dress_style)
    hair.image = random.choice(hair_style)
    shoes.image = random.choice(shoes_style)

def on_mouse_down(pos):
    if dress.collidepoint(pos):
        changestyle(dress,dress_style)
    elif hair.collidepoint(pos):
        changestyle(hair, hair_style)
    elif shoes.collidepoint(pos):
        changestyle(shoes,shoes_style)
    elif button1.collidepoint(pos):
        rand_change()
    elif button2.collidepoint(pos):
        change_all()

pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
1232RvE1232RvE

玩着学py?

点赞0


评论


小河U小河U

????我什么时候发的?

点赞0


评论


SGY酥安SGY酥安

az......

话说你是怎样在PY里导入图片的?(py渣渣中的渣渣)

点赞0


评论


小河U小河U

话说为啥是交作业,你猜(doge)?

点赞0


评论


jo太郎12jo太郎12

请问素材在哪里找的

点赞0


评论