Python猴子穿衣装扮小游戏

猴子穿衣小游戏,这是用python的海龟画图制作的一个小游戏。

编程最重要的是可读性,教小孩的代码,可以用中文,打破常规思维,不要被框框所束缚。本程序新建了一个角色Sprite类,每个道具都是继承自Turtle类。

"""猴子穿衣小游戏,这是用python的海龟画图制作的一个小游戏。"""

from turtle import *

screen = Screen()
screen.title("猴子穿衣 by 李兴球")
screen.bgpic("猴子背景.gif")
screen.setup(800,600)
screen.delay(0)


眼镜表=  ["眼镜1.gif","眼镜2.gif","眼镜3.gif"]
上衣表=  ["上衣1.gif","上衣2.gif","上衣3.gif","上衣4.gif"]
帽子表=  ["帽子1.gif","帽子2.gif","帽子3.gif","帽子4.gif"]
连衣裙表 = ["连衣裙子1.gif","连衣裙子2.gif","连衣裙子3.gif"]
裙子表 = ["裙子1.gif","裙子2.gif","裙子3.gif","裙子4.gif"]
头发表 = ["头发1.gif","头发2.gif","头发3.gif","头发4.gif","头发5.gif","头发6.gif"]

for item in 眼镜表:
    screen.addshape(item)
    
for item in 帽子表:
    screen.addshape(item)
    
for item in 上衣表:
    screen.addshape(item)
    
for item in 裙子表:
    
    screen.addshape(item)
for item in 连衣裙表:
    screen.addshape(item)

for item in 头发表:
    screen.addshape(item)
    

class Sprite(Turtle):
    def __init__(self,造型,x,y): # 造型是增加的形状,x,y用来初始定位
        Turtle.__init__(self)
        self.hideturtle()
        self.penup()
        self.shape(造型)      # 把海龟的形状改为造型,造型是注册好的图片
        self.speed(0)
        self.goto(x,y)
        self.showturtle()
        self.ondrag(self.goto)

You must log in to read the rest of this article. Please log in or register as a user.