python幸运大抽奖大转盘粗犷风格小程序

"""幸运大抽奖小程序,本作品要求安装pygame模块才有声音
按空格键开始抽奖。
"""


# 1、模块导入
import sys
from turtle import *
from random import randint



# 2、屏幕初始化 
screen = Screen()
screen.title("幸运大抽奖 by lixingqiu")
screen.setup(800,600)
screen.bgpic("转盘.png")
screen.delay(0)
vertex = ((0,0),(25,0),(25,100),(50,100),(0,150),(-50,100),(-25,100),(-25,0)) # 顶点表
screen.addshape("bigarrow",vertex)                        # 添加大箭头各顶点到形状列表

# 3、加载造型列表 
sprite1_images = ["anjuli-1.gif","anjuli-2.gif","anjuli-3.gif","anjuli-4.gif","anjuli-5.gif"]
sprite2_images = ["anna-1.gif","anna-2.gif","anna-3.gif"]
sprite3_images = ["ballerina-a.gif","ballerina-b.gif","ballerina-c.gif","ballerina-d.gif"]
sprite4_images = ["breakdancer-1.gif","breakdancer-2.gif","breakdancer-3.gif","breakdancer-4.gif"]
sprite_images = [sprite1_images,sprite2_images,sprite3_images,sprite4_images]
try:
   [screen.addshape(image)  for images in sprite_images for image in images]    # 双重列表推导式
except:
    screen.bye()
    input("造型图片丢失或损坏! 无法注册造型到形状列表")   
    sys.exit()
    
 
# 4、音频初始化 

have_pygame = False
try:
    import pygame
    pygame.mixer.init()
    吱吱声 = pygame.mixer.Sound("转盘转动(短)小.wav")   # 吱吱声.play()
    叮 = pygame.mixer.Sound("叮.wav")
    pygame.mixer.music.load("眉飞色舞.wav")
    pygame.mixer.music.play(-1,0)
    have_pygame = True
except:
    print("Pygame音频初始化错误或找不到音频文件。")
    
本文隐藏内容 登陆 后才可以浏览
sprite1 = Sprite(sprite1_images,-300,200) sprite2 = Sprite(sprite2_images,300,200) sprite3 = Sprite(sprite3_images,-300,-200) sprite4 = Sprite(sprite4_images,300,-200) # 6、箭头角色与旋转 arrow = Turtle(shape = "bigarrow") arrow.color("black","purple") numbers = randint(50,100) # 旋转次数 angle = 30 # 每次旋转的角度 def rotate(): global numbers,angle screen.onkeypress(None,"space") # 取消注册 if numbers: # numbers非0为真 if numbers<30:angle = numbers # 形成减速效果 arrow.rt(angle) numbers = numbers - 1 if have_pygame : 吱吱声.play() screen.ontimer(rotate,30) else: #numbers为0就结束转动了 numbers = randint(80,200) angle = 30 if have_pygame :叮.play() screen.onkeypress(rotate,"space") #重新注册 screen.onkeypress(rotate,"space") screen.listen() screen.mainloop()

python 幸运大抽奖大转盘by李兴球lixingqiu