""" 泡泡摸奖系统.py 在人生的舞台上,你可以单击泡泡摸奖,祝你获得健康,幸福. """ import pygame from winprize.screen import * from winprize.pop import * from winprize.girl import * from time import sleep pygame.mixer.init() bgmusic = "眉飞色舞.wav" pygame.mixer.music.load(bgmusic) pygame.mixer.music.play(-1,0) pop_sound = pygame.mixer.Sound("Pop.wav") imagelist = ["舞台" + str(i) + ".png" for i in range(7)] s = Dynamic_screen(title='泡泡摸奖系统',piclist=imagelist,interval=100) screen = s.screen girl_images = ["qq女孩秀0.gif","qq女孩秀1.gif"] [screen.addshape(image) for image in girl_images] # 注册到形状列表 dance_girl = Girl(girl_images) # 生成后,它会自己"跳舞" all_coordinates=[(-120,90),(-40,90),(40,90),(120,90),(-120,0),(-40,0),\ (40,0),(120,0),(-120,-90),(-40,-90),(40,-90),(120,-90)] ac = all_coordinates # 仅仅是为了缩短代码而定义的别名 pop_image_list = ["泡泡造型1.gif","泡泡造型2.gif","泡泡造型3.gif","泡泡造型4.gif"] [screen.addshape(image) for image in pop_image_list] #注册到形状列表,image为gif图片 # 实例化12个泡泡 pops = [ Pop(pop_image_list,x,y,pop_sound) for x,y in all_coordinates] pop_amount = len(pops) pops[0].prize = "一等奖" pops[1].prize = "二等奖" pops[2].prize = "二等奖" pops[3].prize = "三等奖" pops[4].prize = "三等奖" pops[5].prize = "三等奖" def pop_shuffle(): """按空格键后对泡泡的位置进行随机调换,为了演示交换过程,没有使用shuffle命令""" old_delay = screen.delay() screen.delay(2) screen.onkeypress(None,"space") [pop.set_shake(False) for pop in pops] # 所有泡泡暂停摇摆 sleep(0.5) for i in range(10): index1 = randint(0,pop_amount-1) index2 = randint(0,pop_amount-1) while index1 == index2:index2 = randint(0,pop_amount-1) tmp = ac[index1] # 先保存index1索引号的数据(坐标) ac[index1] = ac[index2] # 设定index1索引号的数据为 index2指向的数据 ac[index2] = tmp # 设定index2索引号的数据为原index1的数据 pops[index1].initxy(ac[index1][0],ac[index1][1]) # 重新设置为初始坐标 pops[index2].initxy(ac[index2][0],ac[index2][1]) # 重新设置为初始坐标 pops[index1].goto(ac[index1]) # 让索引为index1的泡泡到已交换位置的坐标 pops[index2].goto(ac[index2]) # 让索引为index2的泡泡到已交换位置的坐标 sleep(0.1) [pop.set_shake(True) for pop in pops] # 所有泡泡继续摇摆 screen.delay(old_delay) screen.onkeypress(pop_shuffle,"space") screen.onkeypress(pop_shuffle,"space") Pop.wait_all_pop_explode() tip_turtle = Turtle(visible = False) tip_turtle.penup() tip_turtle.sety(-160) def tip(): """祝词""" r,g,b = randint(0,255),randint(0,255),randint(0,255) tip_turtle.pencolor(r,g,b) wd = "按空格键重排泡泡顺序,单击泡泡即是摸奖。" tip_turtle.write(wd,align='center',font=("黑体",14,"normal")) tip_turtle.screen.ontimer(tip,1000) tip() screen.listen() screen.mainloop()
下载完整源代码与素材,包括各子模块,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)