建立Gird列表存储小拼图的基本信息
Gird=[]
for i in range(6):
for j in range(4):
Square=Actor("girl_06")
Square.left=Square_size*j
Square.top=Square_size*i
Gird.append(Square)
修改draw()绘制函数
建立循环绘制Gird列表中的所有小拼图
def draw():
screen.clear()
for Square in Gird:
Square.draw()
执行效果如图所示:
Squares=[Actor("girl_01"),Actor("girl_02"),Actor("girl_03"),Actor("girl_04")
,Actor("girl_05"),Actor("girl_06"),Actor("girl_07"),Actor("girl_08")
,Actor("girl_09"),Actor("girl_10"),Actor("girl_11"),Actor("girl_12")
,Actor("girl_13"),Actor("girl_14"),Actor("girl_15"),Actor("girl_16")
,Actor("girl_17"),Actor("girl_18"),Actor("girl_19"),Actor("girl_20")
,Actor("girl_21"),Actor("girl_22"),Actor("girl_23"),Actor("girl_24")
]
修改Gird列表中的图块对象,通过索引调用Squares中的小拼图。
Square=Squares[i*4+j]
执行效果如图所示:
完整代码如下:
# 利用列表存储所有的图块信息 将完整的图片显示出来
import pgzrun # 导入游戏库
TITLE="pgzrun 拼图游戏" # 窗口标题
Square_size=125 # 设定移动图块的大小
WIDTH=Square_size*4 # 窗口宽度
HEIGHT=Square_size*6 # 窗口高度
Squares=[Actor("girl_01"),Actor("girl_02"),Actor("girl_03"),Actor("girl_04")
,Actor("girl_05"),Actor("girl_06"),Actor("girl_07"),Actor("girl_08")
,Actor("girl_09"),Actor("girl_10"),Actor("girl_11"),Actor("girl_12")
,Actor("girl_13"),Actor("girl_14"),Actor("girl_15"),Actor("girl_16")
,Actor("girl_17"),Actor("girl_18"),Actor("girl_19"),Actor("girl_20")
,Actor("girl_21"),Actor("girl_22"),Actor("girl_23"),Actor("girl_24")
]
Gird=[]
for i in range(6):
for j in range(4):
Square=Squares[i*4+j]
Square.left=Square_size*j
Square.top=Square_size*i
Gird.append(Square)
def draw():
screen.clear()
for Square in Gird:
Square.draw()
def update():
pass
pgzrun.go()
pgzrun拼图游戏素材包下载