本文整理汇总了Python中simpleguitk.create_timer函数的典型用法代码示例。如果您正苦于以下问题:Python create_timer函数的具体用法?Python create_timer怎么用?Python create_timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_timer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_bonus
def process_bonus(bonus):
global lives, explosion_group, cant_rocks, rock_group, timer3, score, \
immortal, scoreBonus, seconds, functionTimer
if bonus.type == 3: # lives++
lives += 1
elif bonus.type == 4: # exploit all the asteroids
copy = rock_group.copy()
for i in copy:
explosion_group.add(Sprite(i.get_position(), [0, 0], 0, 0,
explosion_image, explosion_info,
WIDTH, HEIGHT, explosion_sound))
rock_group.discard(i)
cant_rocks -= 1
score += 1
else:
if bonus.type == 2: #each asteroid is +2
scoreBonus = True
immortal = False
elif bonus.type == 1: #the asteroids not hurt you
immortal = True
scoreBonus = False
if timer3 is not None:
timer3.stop()
seconds = 0
timer3 = simplegui.create_timer(1000, timer_bonus_1_2)
tick_tock_sound.rewind()
tick_tock_sound.play()
timer3.start()
示例2: move
def move():
global snake, bean, direction, gameover, score, time_interval, timer
if not gameover:
if direction == RIGHT:
head = [snake[0][0]+1, snake[0][1]]
elif direction == UP:
head = [snake[0][0], snake[0][1]-1]
elif direction == LEFT:
head = [snake[0][0]-1, snake[0][1]]
elif direction == DOWN:
head = [snake[0][0], snake[0][1]+1]
# 检查游戏结束条件
if head[0] >= COLS or head[0] < 0 or head[1] >= ROWS or head[1] < 0 or (head in snake):
gameover = True
return
snake.insert(0, head)
tail = snake.pop()
if bean in snake: # 如果吃到豆子
bean = create_bean()
snake.append(tail)
score += 1
if score > 0 and score % 5 == 0 and time_interval > 50:
simplegui.timers.destroy() # 先销毁原有 timer,再创建新的 timer
time_interval /= 1.2
timer = simplegui.create_timer(time_interval, move)
timer.start()
示例3: main
def main():
global TIME_INTERVAL, frame, timer
#create a timer with timed event
timer = simplegui.create_timer(TIME_INTERVAL, incrementTime)
#create frame
frame = createFrame()
#start frame
frame.start()
示例4: reset
def reset():
""" Reset stopwatch and score """
global timer, counter, message, attempts, hits, is_running, sucs_message
timer.stop()
is_running = False
timer = simplegui.create_timer(100, tick)
counter = 0
attempts = 0
hits = 0
sucs_message = ""
示例5: timer_handler
def timer_handler():
global x
x += 4
print x
print time.time()
print ""
global timer
if x >= 16:
timer.stop()
timer = simpleguitk.create_timer(500, timer_handler)
timer.start()
示例6: play
def play():
global snake, bean, direction, gameover, score, time_interval, timer
# 如果有正在运行的定时器,需要先把它停下
if timer is not None and timer.is_running():
timer.stop()
# 创建定时器
timer = simplegui.create_timer(time_interval, move)
timer.start()
# 代码写在下面
pass
示例7: createWorld
def createWorld(self):
world = gui.create_frame("Robot World",self.worldX,self.worldY)
world.set_canvas_background(GUI.WORLD_COLOR)
self.txtSetDist = world.add_input("Set Distance", self.txtDestDistance,50)
self.btnSetDist = world.add_button("Set Distance",self.setDistHandler,50)
self.btnMove = world.add_button("Move",self.moveHandler, 50)
timer = gui.create_timer(500,self.timerHandler)
world.set_draw_handler(self.renderingHandler)
timer.start()
world.start()
示例8: play
def play():
global snake, bean, direction, gameover, score, time_interval, timer
# 如果有正在运行的定时器,需要先把它停下
if timer is not None and timer.is_running():
timer.stop()
# 创建定时器
timer = simplegui.create_timer(time_interval, move)
timer.start()
snake = create_snake()
bean = create_bean()
direction = LEFT
score = 0
gameover = False
time_interval = 200
示例9: __init__
def __init__(self, puzzle):
"""
Create frame and timers, register event handlers
"""
self._puzzle = puzzle
self._puzzle_height = puzzle.get_height()
self._puzzle_width = puzzle.get_width()
self._frame = simplegui.create_frame("The Fifteen puzzle",
self._puzzle_width * TILE_SIZE,
self._puzzle_height * TILE_SIZE)
self._solution = ""
self._current_moves = ""
self._frame.add_button("Solve", self.solve, 100)
self._frame.add_input("Enter moves", self.enter_moves, 100)
self._frame.add_button("Print moves", self.print_moves, 100)
self._frame.set_draw_handler(self.draw)
self._frame.set_keydown_handler(self.keydown)
self._timer = simplegui.create_timer(50, self.tick)
self._timer.start()
self._frame.start()
示例10: key_down
def key_down(key):
if key == simplegui.KEY_MAP["space"]:
game_begin()
def input_handler(text_input):
global lives
if text_input.isdigit():
lives = int(text_input)
# initialize frame
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)
inp = frame.add_input('初始阳光:', input_handler, 50)
inp.set_text(1000)
# register handlers
frame.set_draw_handler(draw)
frame.set_keydown_handler(key_down)
frame.set_mouseclick_handler(mouseclick)
timer = simplegui.create_timer(random.randint(500, zombie_interval), zombie_spawner)
timer1 = simplegui.create_timer(5000.0, sunshine_spawner)
timer2 = simplegui.create_timer(1000.0, bullet_spawner)
timer3 = simplegui.create_timer(100.0, flower_sunshine_spawner)
# get things rolling
timer.start()
timer1.start()
timer2.start()
timer3.start()
frame.start()
示例11: draw
def draw(canvas):
line_width = random.randrange(0,6,2)
line_color = random.choice(color_list)
fill_color = random.choice(color_list)
font_color = random.choice(color_list)
if choice ==1:
radius = random.randint(1,10)
circle_x = random.randrange(radius, WIDTH-radius)
circle_y = WIDTH/2 * random.random()
radius = random.randint(1,20)
canvas.draw_circle([circle_x,circle_y], radius, line_width, line_color, fill_color)
if choice == 2:
point_list = [[random.randrange(0, WIDTH),random.randint(0,HEIGHT)],[WIDTH/2,HEIGHT/2]]
canvas.draw_polygon(point_list, line_width, line_color, fill_color)
if choice == 3:
point =[random.randrange(0, WIDTH),random.randint(0,HEIGHT)]
font_size = random.choice([6,8,12,24,36,64])
canvas.draw_text(text, point, font_size, font_color)
frame = simplegui.create_frame("屏幕保护程序",400, 400)
frame.add_button("画圆效果", click1, 50)
frame.add_button("折线效果", click2, 50)
frame.add_button("文字效果", click3, 50)
frame.add_input("请输入出现在屏保上的文字:",input,100)
frame.add_button("清空", pause, 50)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(5000,timer_handler)
frame.start()
示例12: Grid
timer.stop()
inplay = True
grid = Grid()
score = 0
current_shape = create_shape()
timer.start()
def keydown(key):
if key == simplegui.KEY_MAP['space']:
current_shape.rotate(grid)
if key == simplegui.KEY_MAP['left']:
current_shape.move('left', grid)
if key == simplegui.KEY_MAP['right']:
current_shape.move('right', grid)
if key == simplegui.KEY_MAP['down']:
current_shape.move('down', grid)
# 创建用户界面
frame = simplegui.create_frame("俄罗斯方块", WIDTH, HEIGHT)
frame.set_draw_handler(draw)
frame.set_keydown_handler(keydown)
# 创建按钮
frame.add_button("开始游戏", play, 80)
# 创建定时器
timer = simplegui.create_timer(TIME_INTERVAL, move)
play()
frame.start()
示例13: keydown
# 按键事件响应函数
def keydown(key):
global score
try:
ch = chr(key)
except: # 捕捉 TypeError 或其它异常
return # 不做任何处理
else:
pass
# 代码填在这里
# 换一个词
def change_word():
global word, flag, pointer, score
pass
# 创建用户界面
frame = simplegui.create_frame("疯狂英语", WIDTH, HEIGHT)
frame.set_canvas_background("White")
frame.set_draw_handler(draw)
frame.set_keydown_handler(keydown)
# 创建按钮
frame.add_button("开始游戏", play, 80)
# 创建定时器
timer = simplegui.create_timer(TIME_INTERVAL, change_word)
play()
frame.start()
示例14: demo1
def demo1():
# Register handler
timer = simplegui.create_timer(1000, tick)
# Start timer
timer.start()
示例15: start_game
# 为游戏开始或重新开始初始化全局变量,也是鼠标点击按钮的事件处理函数
def start_game():
global prime_sentence_list, stopped_box, rising_box,current_section_list, has_rising_box, game_over, score, last_four_box
score = 0
label.set_text("游戏得分 = 0分")
game_over = False
prime_sentence_list = read_from_file('三字经.txt')
stopped_box = set([])
last_four_box = []
current_section_list = generate_current_section_list()
rising_sentence = current_section_list.pop()
rising_box = Box([0,canvas_height], box_width, box_height, text_shuffle(rising_sentence[1:]), rising_sentence[1:], int(rising_sentence[0]))
has_rising_box = True
# 创建窗口初始化画布
frame = simplegui.create_frame("挑战《三字经》", canvas_width, canvas_height)
label = frame.add_label("游戏得分 = 0分")
# 注册事件处理函数
frame.set_keydown_handler(keydown) # 按键处理,每次按键会调用keydown函数
frame.set_draw_handler(draw) # 显示处理,每秒调用draw函数60次
timer = simplegui.create_timer(1000.0, box_spawner) # 每秒调用box_spawner函数1次
button = frame.add_button('重新开始游戏', start_game, 100) # 鼠标每次点击“重新开始游戏”按钮,调用start_game函数1次
# 启动游戏
start_game() # 为游戏开始或重新开始初始化全局变量
timer.start() # 启动定时器
frame.start() # 显示窗口