这是用海龟画图模块制作的一个类。应用于一个小游戏,玛丽的算术。
以下是部分代码预览:
"""
玛丽的算术之砖块类。
本程序定义了一个砖块类,
配合超级玛丽的算术小游戏而设计的。
"""
from turtle import *
class Brick(Turtle):
"""
继承自Turtle类的砖块类
"""
def __init__(self,images,x,y,w,h,mario):
"""
初始化方法
images:造型序列
pos:坐标
w,h:宽高
mario:超级玛丽
"""
Turtle.__init__(self,visible=False)
self.up()
self.speed(0)
self.images = images
self.shape_index = 0
self.shape(images[0]) # 初始造型
self.shape_amount = len(images)# 造型数量
self.goto(x,y)
self.left = x - w//2 # 重定义left
self.right = x + w//2 # 重定义right
self.top = y + h//2 # 定义top
self.bottom = y - h//2 # 定义bottom
self.mario = mario
self.nobumped = True
self.wait_bump()
self.st()
self.screen.update()
def wait_bump(self):
"""等待是否被玛丽碰到"""
def alt_costume(self):
"""切换造型"""
if __name__ == "__main__":
main()
如需要查看所有源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

