600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python的turtle模块制作的打地鼠小游戏/4/9版

python的turtle模块制作的打地鼠小游戏/4/9版

时间:2019-10-09 02:01:56

相关推荐

python的turtle模块制作的打地鼠小游戏/4/9版

又过了一年了。这一年我的python编程水平得到了非常大的进步。从用turtle制作动画与游戏,然后用pygame做动画与游戏,接着是用arcade做街机游戏,pymunk物理引擎等等。看看一年前的代码,简直就是shit,唉不多说了。下面是最新版本的打地鼠类

需要本程序的完整代码请到本人的博客上去吧。

"""python的turtle模块制作的打地鼠小游戏,用pygame的混音器配音,此版本为/4/9修改。海龟的图片造型不能旋转,解决方案是用多个造型,但是没有内置的碰撞检测,所以此版本没有加榔头,基本不再更新。更好的版本应该用pygame或arcade等模块来制作,有需要制作的可以联系我。"""__author__ = "李兴球"__date__ = "/4/9"import os,sysfrom turtle import *from random import *from time import sleepimport pygameclass Mouse(Turtle):"""定义地鼠类,用来生成地鼠"""clicks = 0 # 统计单击数量def __init__(self,image,position,sound): """初始化父类,可能是隐藏也可能是显示,造型为地鼠图片,要先注册到海龟画图屏幕中的造型列表"""Turtle.__init__(self,visible=choice([False,True]),shape=image)self.penup() self.speed(0)# 设定速度self.goto(position)self.sound = sound# 声音效果self.hideshow() # 调用方法self.onclick(self.hide)# 绑定单击事件def hideshow(self):if self.isvisible():self.hideturtle()else:self.showturtle()self.screen.ontimer(self.hideshow,randint(1009,3009))def hide(self,x,y):Mouse.clicks = Mouse.clicks + 1self.hideturtle()self.sound.play()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。