当前位置: 首页>>代码示例>>Python>>正文


Python simpleguitk.create_timer函数代码示例

本文整理汇总了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()
开发者ID:ErisoHV,项目名称:Asteroids,代码行数:30,代码来源:Asteroids.py

示例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()
开发者ID:wzmdream,项目名称:similarity_check,代码行数:27,代码来源:snake_solution.py

示例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()
开发者ID:CardenB,项目名称:pyGames,代码行数:9,代码来源:StopWatchGame.py

示例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 = ""
开发者ID:vogonwann,项目名称:coursera,代码行数:10,代码来源:stopwatch.py

示例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()
开发者ID:onthrak,项目名称:python_courses,代码行数:11,代码来源:timers+start+and+stop.py

示例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  
开发者ID:wzmdream,项目名称:similarity_check,代码行数:11,代码来源:snake.py

示例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()
开发者ID:monica-p,项目名称:YorkU-Minnow,代码行数:14,代码来源:GUI.py

示例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  
开发者ID:wzmdream,项目名称:similarity_check,代码行数:15,代码来源:snake_solution.py

示例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()
开发者ID:flail-monkey,项目名称:principles1,代码行数:21,代码来源:poc_fifteen_gui.py

示例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()
开发者ID:wzmdream,项目名称:similarity_check,代码行数:30,代码来源:pvz1.py

示例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()
开发者ID:wzmdream,项目名称:similarity_check,代码行数:31,代码来源:ScreenSave.py

示例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()
开发者ID:wzmdream,项目名称:similarity_check,代码行数:30,代码来源:tetris.py

示例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()
开发者ID:wzmdream,项目名称:similarity_check,代码行数:31,代码来源:crazy_english.py

示例14: demo1

def demo1():
    # Register handler
    timer = simplegui.create_timer(1000, tick)
    # Start timer
    timer.start()
开发者ID:tdongsi,项目名称:python,代码行数:5,代码来源:SimpleGuiDemo.py

示例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()    # 显示窗口
开发者ID:wzmdream,项目名称:similarity_check,代码行数:29,代码来源:ThreeCharacterPrimer.py


注:本文中的simpleguitk.create_timer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。