发一下自己写的公司抽奖程序。。
需求:公司年会要一个抽奖程序,转盘上的每一个人名是随机中奖的,中奖后的人不可以再次中奖,按住抽奖,就会一直在转,放开后,要再转一两圈才停。
呵,刚好自己在学python cocos2d, 就用这个刚学的东东,虽然只学了点皮毛..直接上源码
# coding:utf-8
#
import sys
# import os
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
# 解决程序中要显示中文问题
reload(sys)
sys.setdefaultencoding('utf8')
from pyglet import image, font
from pyglet.gl import *
from pyglet.window import key
from cocos.actions import *
from cocos.director import director
from cocos.layer import Layer
from cocos.layer import ColorLayer
from cocos.scene import Scene
from cocos.sprite import Sprite
from cocos.text import *
from cocos.menu import *
import random
from cocos.audio.effect import Effect
consts_window = {
"width": 680,
"height": 700,
"vsync": True,
"resizable": True,
'audio_backend':'sdl'
}
def get_sprite_test( index ):
d = tests[index]
return Scene( d( index ) )
class SpriteLayer( Layer ):
is_event_handler = True #: enable pyglet's events
def __init__( self, index=1 ):
super(SpriteLayer, self ).__init__()
self.index = index
self.top_text = "广州德瀚信息信息科技有限公司-年会抽奖"
self.image = pyglet.resource.image('r1.png',0.01)
# self.image = image.AnimationFrame(image.load('r1.png'),0.1)
self.image.anchor_x = self.image.width / 2
self.image.anchor_y = self.image.height / 2
self.rimage = pyglet.resource.image('r2.png',0.01)
# self.rimage = image.AnimationFrame(image.load('r2.png'),0.1)
self.rimage.anchor_x = self.image.width / 2
self.rimage.anchor_y = self.image.height / 2
self.bgimage = pyglet.resource.image('bg1.png')
self.bgimage.anchor_x = self.image.width / 2
self.bgimage.anchor_y = self.image.height / 2
self.pressbgimage = pyglet.resource.image('bg2.png')
self.pressbgimage.anchor_x = self.image.width / 2
self.pressbgimage.anchor_y = self.image.height / 2
self.prizeimage = pyglet.resource.