"""这是一个双人小游戏,在屏幕上会时不时的出现一些成语,玩家操作小方块去碰这些成语即可得分。"""
from turtletools import * #从turtletools模块导入所有命令,init_screen,init_sound,countdown
from writer import * #从writer模块导入Writer类
from idiom import * #导入成语表 idiomList和Idiom类
from square import * #导入方块类 Square
from time import sleep
def clearlines():
"""清除方块所画的线条图形"""
[square.clear() for square in squares]
def end_of_countdown():
"""倒计时结束游戏"""
global gametime
if gametime>0:
gametime = gametime - 1
screen.ontimer(end_of_countdown,1000)
else:
"""停止所有方块的移动"""
[square.stop() for square in squares]
idiom.stop() #成语停止
screen.bgpic(endimage) #显示结束画面
info = [ square.name + ":" + str(square.score) for square in squares]
info = ",".join(info) #连接列表每一项
myfont = ("楷体",24,"normal")
end_writer = Writer(0,-50,myfont,info,13000,screen)
screen.onclick(lambda x,y:screen.bye()) #单击屏幕关闭窗口
if __name__=="__main__":
"""初始化屏幕"""
game_name = "抢收成语"
screen_width,screen_height = 480,360 #定义全局变量屏幕宽度和高度
ps = game_name,"black",screen_width,screen_height,"background2.gif"
screen = init_screen(*ps) #调用初始化屏幕函数
"""把每个成语gif图片注册到形状列表,idiomList从模块idiom中来"""
[screen.addshape(idiom) for idiom in idiomList] #注册所有成语到形状列表
"""初始化声音"""
have_pygame,bumpsound = init_sound("Popcorn1.wav","叮.wav")
"""写游戏的题目"""
myfont = ("黑体",32,"normal")
title_writer = Writer(0,100,myfont,game_name,3,screen) #Writer类
"""写版权所有"""
copy_right = "版权所有,Copy right by lxq"
ps = 0,50-screen_height/2 ,("黑体",12,"normal"),copy_right,3,screen
copyright_writer = Writer(*ps)
"""倒计时显示,准备开始游戏"""
countdown(4,myfont,"cyan") #4,3,2,1倒计时
"""生成红色小方块"""
ps = screen,"红点",-50,0,180,"red","Up","Down","Left","Right"
redsquare = Square(*ps) #方块类,生成后会自己移动
"""生成蓝色小方块"""
ps = screen,"蓝点",50,0,0,"blue","w","s","a","d"
bluesquare = Square(*ps) #方块类,生成后会自己移动
"""把小方块装到列表里,方便管理"""
squares = [redsquare,bluesquare]
"""生成一个成语对象,成语随机出现"""
ps = 137,42,[redsquare,bluesquare],screen,have_pygame,bumpsound,game_name
idiom = Idiom(*ps) #生成后,它等待被撞,然后换造型
"""注册空格键事件,如果按空格键,那么清除所有笔迹"""
screen.onkeypress(clearlines,"space") #按空格键清除所画的图形
"""倒计时结束,显示画面"""
endimage = "结束画面.png"
gametime = 60 #设置游戏时间
end_of_countdown() #异步等待游戏结束
"""设置屏幕焦点,进入主循环"""
screen.listen()
screen.mainloop()
"""以上程序只是主程序,需要各个模块代码及素材请联系风火轮少儿编程李兴球先生"""