Exemplo n.º 1
0
 def __init__(self):
     self.tetris = {}
     self.pile = Pile()
     self.time = 0
     self.state = 0
     self.score = 0
     self.chain = 0
     self.points = []
     self.move_dict = {}
     self.best = 0
     self.time1 = simplegui.create_timer(500, self.tetri_down)
     self.time2 = simplegui.create_timer( 20, self.tetri_down)
     self.time3 = simplegui.create_timer(120, self.pile_update)
     self.timer = simplegui.create_timer(1000, self.count_down)
     self.frame = simplegui.create_frame('Tetris', width, height)
Exemplo n.º 2
0
def reset_handler():
    global timer, t, attempts, score
    timer.stop()
    t = 0
    attempts = 0
    score = 0
    timer = simplegui.create_timer(interval, timer_handler)
Exemplo n.º 3
0
    def __init__(self):
        """
        Set elements of the game.
        """
        self.loaded = False

        self.keydown_left = False
        self.keydown_right = False
        self.lives = 3
        self.my_ship = None
        self.nb_bombs = None
        self.score = 0
        self.started = False
        self.time = 0

        self.explosions = []
        self.live_explosions = []
        self.missiles = []
        self.rocks = []

        self.animate_background_active = True
        self.music_active = True
        self.sounds_active = True
        self.timer = simplegui.create_timer(1000, self.rock_spawner)

        self.img_infos = None
        self.medias = None
 def __init__(self,center_xy = (30,200),radius = 10 ,motion_vector=(1.0,0.5)):
     self.xy = center_xy
     self.radius = radius
     self.radius_squared = radius * radius
     self.color = "orange"
     
     self.tics = 0
     self.last_move_1_or_more = (0,0)
     self.mv = motion_vector # px/s x , px/s y
     self.timer_interval = 20.0
     self.tic_freq = self.timer_interval / 1000.0
     self.d_per_tic = (self.tic_freq * self.mv[0],self.tic_freq * self.mv[1])
     
     if self.d_per_tic[0] == 0.0:
         move_freq_x =  999999
     else:
         move_freq_x = abs(1.0 / self.d_per_tic[0])
         
     if self.d_per_tic[1] == 0.0:
         move_freq_y = 999999
     else:
         move_freq_y = abs(1.0 / self.d_per_tic[1])
     self.move_freq = (move_freq_x,move_freq_y)
     
     self.timer = simplegui.create_timer(int(self.timer_interval),self.tic)
     self.timer.start()
     
     self.last_hit = -1
     
     self.walls = []
Exemplo n.º 5
0
def gameWindow_init():
    global pong_frame, reset_timer

    # Create Game Window
    pong_frame = simplegui.create_frame("Pong", roomRect.getWidth(), roomRect.getHeight(), 300)
    game_instructions = []
    game_instructions.append(pong_frame.add_label("Welcome to Pong!"))
    game_instructions.append(pong_frame.add_label(""))
    game_instructions.append(pong_frame.add_label("Up and Down arrow keys control the Blue paddle"))
    game_instructions.append(pong_frame.add_label(""))
    game_instructions.append(pong_frame.add_label("W and S keys control the Red paddle"))
    game_instructions.append(pong_frame.add_label(""))
    game_instructions.append(pong_frame.add_label("Click anywhere in the game window to start"))
    game_instructions.append(pong_frame.add_label(""))
    game_instructions.append(pong_frame.add_label("May the force be with you."))
    game_instructions.append(pong_frame.add_label(""))

    # Game Window Buttons and Controls
    # resetButton = pong_frame.add_button("New Game", new_game, 150)
    pong_frame.add_button("Single Player (vs Computer)", singlePlayer, 250)
    pong_frame.add_button("2 Player (Restart)", twoPlayer, 250)

    # Timers
    reset_timer = simplegui.create_timer(1000, reset_pause)

    # Register event handlers
    pong_frame.set_keydown_handler(keydown)
    pong_frame.set_keyup_handler(keyup)
    pong_frame.set_draw_handler(draw)
    pong_frame.set_mouseclick_handler(mouseclick_startGame)
Exemplo n.º 6
0
def rock_spawner():
global rock_group
if started:
if len(rock_group) < 12:
rock_pos = [random.randrange(0, WIDTH), random.randrange(0, HEIGHT)]
rock_vel = [random.random() * ROCK_VEL_FACTOR - ROCK_VEL_FACTOR / 2, random.random() * ROCK_VEL_FACTOR - ROCK_VEL_FACTOR / 2]
rock_avel = random.random() * ROCK_AVEL_FACTOR - ROCK_AVEL_FACTOR / 2
a_rock = Sprite(rock_pos, rock_vel, 0, rock_avel, asteroid_image, asteroid_info)
# add rock to group only if its not colliding with the ship
if not a_rock.collide(my_ship):
rock_group.add(a_rock) 

# Main part 
# Declare frame
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)
# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
rock_group = set([])
explosions_group = set([])
missiles_group = set([])

# register handlers
frame.set_keyup_handler(keyup)
frame.set_keydown_handler(keydown)
frame.set_mouseclick_handler(click)
frame.set_draw_handler(draw)

timer = simplegui.create_timer(1000.0, rock_spawner)

# get things rolling
timer.start()
frame.start()
 def __init__(self,interval):
     self.interval = interval
     self.timer = simplegui.create_timer(interval, self.tic)
     self.step = 1
     self.tic_signal = Signal("tic")
     SignalSender.__init__(self)
     print('TimerManager __init__ done')
Exemplo n.º 8
0
def deal():
    global outcome, in_play, deck, dealer, player
    global timer, status, dealed, score
    
    if in_play:
        in_play = False
        dealed = True
        status = LOOSE
        timer = simplegui.create_timer(2000, timer_handler)
        timer.start()
        score -= 1
    else:
        in_play = True
        dealed = False

    # your code goes here
    deck = Deck()
    dealer = Hand()
    player = Hand()
    
    deck.shuffle()    
    i=0
    while i<2:
        player.add_card(deck.deal_card())
        dealer.add_card(deck.deal_card())
        i+=1
        
    #print "Player " + str(player)
    #print "Dealer " + str(dealer)
    
    outcome = "Hit or Stand?"
Exemplo n.º 9
0
def setup_frame():
    # initialize stuff
    global timer, quiz, questions
    quiz = Quiz(questions)
    frame = simplegui.create_frame("QUIZ", WIDTH, HEIGHT)
    timer = simplegui.create_timer(1000, timer_handler)
    frame.set_canvas_background("Pink")
    # register handlers
    #frame.set_keyup_handler(keyup)
    #frame.set_keydown_handler(keydown)
    #frame.set_mouseclick_handler(click)
    frame.set_draw_handler(draw)
    frame.add_label("Game Controls")
    frame.add_button("Restart", restart, 100)
    frame.add_button("Next Question", nextQuestion, 100)
    frame.add_button("Review Question", prev, 100)
    # frame.add_button("Reset Question", resetQuestion, 100)
    frame.add_label("Select Your Answer")
    frame.add_button("A", selectA, 100)
    frame.add_button("B", selectB, 100)
    frame.add_button("C", selectC, 100)
    frame.add_button("D", selectD, 100)
    # get things rolling
    init_game()
    frame.start()
def init():
    # initialize frame
    global my_ship, a_missile, frame, timer, upgrade_number, upgrade_dist
    frame = simplegui.create_frame("Asteroids, by dare7", WIDTH, HEIGHT)
    upgrade_number = frame.add_button("+1 missile for %s$" % str(upgrade_cost), upgrade_count, 180)
    upgrade_dist = frame.add_button("+1 missile range %s$" % str(upgrade_cost), upgrade_range, 180)
    frame.add_button("Reset all", full_reset, 180)
    frame.add_button("Quit", quit, 180)
    # initialize ship and two sprites
    my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
    #a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, 0, asteroid_image, asteroid_info)
    #a_missile = Sprite([2 * WIDTH / 3, 2 * HEIGHT / 3], [-1,1], 0, 0, missile_image, missile_info, missile_sound)
    # register handlers
    frame.set_draw_handler(draw)
    frame.set_keydown_handler(key_down)
    frame.set_keyup_handler(key_up)
    frame.set_mouseclick_handler(click)
    frame.add_label("Shoot stars!")
    frame.add_label("Earn money!")
    frame.add_label("Avoid collision!")
    frame.add_label("Upgrade ship!")
    frame.add_label("")
    frame.add_label("Controls:")
    frame.add_label("Up: accelerate")
    frame.add_label("Left, right: turn")
    frame.add_label("Space: shoot")

    timer = simplegui.create_timer(1000.0, rock_spawner)

    # get things rolling
    timer.start()
    frame.start()
Exemplo n.º 11
0
 def __init__(self, delay):
     # sets the initial time to 0
     self.time = 0
     # sets the delay
     self.delay = delay
     # creates a timer
     self.timer = simplegui.create_timer(delay, self.count)
Exemplo n.º 12
0
    def start(self):
        self.img_loader.start()

        frame = simplegui.create_frame(
            self.title,
            self.width,
            self.height
            )

        frame.set_draw_handler(self.draw_handler)
        frame.set_mouseclick_handler(self.mouse_click_handler)

        frame.set_canvas_background("#87CEEB")

        frame.start()

        self.init_balls()
        self.init_clouds(2)
        self.cloud_timer = simplegui.create_timer(
                            10 * 1000,
                            self.add_cloud)
        self.cloud_timer.start()

        frame.add_button("Clear sky", self.clear_clouds)
#        frame.add_button("Add cloud", self.add_cloud)
        self.rs_button = frame.add_button("Enable radius shrink", self.toggle_radius_shrink)
Exemplo n.º 13
0
def click_dec():
        global timer , interval
        if timer.is_running():
            timer.stop()
            interval = interval+200 
            timer = simplegui.create_timer(interval, timer_handler)
            timer.start()
Exemplo n.º 14
0
    def start(self):
        """
        Start calculation and drawing.

        See `draw_fct()`.
        """
        if self._timer is not None:
            self.stop()

        self._fps = 0
        self._nb_frames_drawed = 0
        self._nb_seconds = 0

        try:
            from simplegui import create_timer
        except ImportError:
            from SimpleGUICS2Pygame.simpleguics2pygame import create_timer

        def update():
            """
            Update counters.
            """
            if self._timer is not None:
                self._nb_seconds += 1
                self._fps = int(round(float(self._nb_frames_drawed)
                                      / self._nb_seconds))

        self._timer = create_timer(1000, update)

        self._timer.start()
Exemplo n.º 15
0
def click_acc():
        global timer , interval 
        if timer.is_running():
            timer.stop()
            #防止变量变为0
            interval = interval/2 + 1
            timer = simplegui.create_timer(interval, timer_handler)
            timer.start()
Exemplo n.º 16
0
def reset():
    global t, curr_time, x, y, running
    x = 0
    y = 0
    running = False
    t.stop()
    t = simplegui.create_timer(100, tick)
    curr_time = 0
def timer_handler():
    global Count, timer
    Count += 1
    print Count
    if Count == 10:
        timer.stop()
        timer = simplegui.create_timer(1000, timer_handler)
        timer.start()
Exemplo n.º 18
0
    def __init__(self, images, finished_callback=None, check_interval=250):
        self.images = images
        self.images_len = len(images)
        self.timer = simplegui.create_timer(check_interval, self._timer_handler)
        self.finished_callback = finished_callback

        self.total_count = len(images)
        self.loaded_count = 0
        self.progress = 0
Exemplo n.º 19
0
def handle_timer():
    global gbl_timer
    global gbl_timer_is_runing
    bool( gbl_timer_is_runing )
    if  gbl_timer_is_runing == False:
        if gbl_timer == None:
            gbl_timer = simplegui.create_timer( gbl_timer_interval, handle_timer_event)
        gbl_timer.start()
        gbl_timer_is_runing = 1
Exemplo n.º 20
0
def auto_review():
    global timer
#点击自动回放开关   
    if timer.is_running():      
        timer.stop()
    else:
        timer = simplegui.create_timer(interval,timer_handler)
        timer.start()
    pass
Exemplo n.º 21
0
def spawn_ball():
    global ball_pos, ball_v, direction 
    def faqiu():
        global ball_v
        ball_v= [random.randrange(2,4)*direction, random.randrange(1, 3)*random.choice([1,-1])]  
        timer.stop()
    ball_pos = [WIDTH/2,HEIGHT/2]    
    ball_v= [0,0]
    timer = simplegui.create_timer(1000, faqiu)    
    timer.start()
Exemplo n.º 22
0
def reset_button_handler():
    global a, bc, d, Stop
    a = 0
    bc = 0
    d = 0
    t="0000"
    timer = simplegui.create_timer(100, timer_handler)
    if Stop:
       Stop=False 
       timer.start()
Exemplo n.º 23
0
def reset():
    global timer, time, sec, min, mil, count, asserts
    timer.stop()
    timer = simplegui.create_timer(100,time_handler)
    time = 0
    min = 0
    sec = 0
    mil = 0
    count = 0
    asserts = 0
Exemplo n.º 24
0
def go():
    with open('floorplan.txt','r') as f:
        for line in f:
            args = line.strip().split(',')
            if args[0] == 'width':
                globals.board_size[0] = int(args[1])
            elif args[0] == 'height':
                globals.board_size[1] = int(args[1])
            elif args[0] == 'bay':
                globals.bays.add(classes.bay(int(args[1]), int(args[2])))
            elif args[0] == 'barrier':
                globals.barriers.add(classes.barrier(int(args[1]), int(args[2])))
            elif args[0] == 'dropoff_point':
                globals.dropoff_points.add(classes.dropoff_point(int(args[1]), int(args[2])))
            elif args[0] == 'tote':
                globals.totes.append(classes.tote(int(args[1]), int(args[2]), random.randint(1,10)))
    
    globals.frame = simplegui.create_frame('Warehouse Man', globals.grid_size * globals.board_size[0], globals.grid_size * globals.board_size[1])
    globals.frame.set_canvas_background('white')
    globals.frame.set_draw_handler(e.draw_handler)
    globals.frame.set_keydown_handler(e.keydown_handler)
    globals.frame.set_keyup_handler(e.keyup_handler)
    
    cadence = simplegui.create_timer(100, e.poll_keyboard)
    globals.timers.add(cadence)
    tote_generator_timer = simplegui.create_timer(60/globals.totes_per_minute * 1000, e.generate_tote)
    globals.timers.add(tote_generator_timer)
    cleanup_timer = simplegui.create_timer(1000, helpers.clean_up_totes)
    globals.timers.add(cleanup_timer)
    order_create_timer = simplegui.create_timer(60/globals.orders_per_minute * 1000, helpers.place_order)
    globals.timers.add(order_create_timer)
    order_countdown_timer = simplegui.create_timer(1000, e.age_orders)
    globals.timers.add(order_countdown_timer)

    globals.packer = classes.player('Packer', 13, 8, 'blue')
    globals.picker = classes.player('Picker', 2, 8, 'cyan')
    globals.active_player = globals.packer
    globals.inactive_player = globals.picker
    
    e.generate_tote()
    helpers.start_timers()
    globals.frame.start()
Exemplo n.º 25
0
    def run_game(self):
        frame = simplegui.create_frame('Asteroids', WIDTH, HEIGHT)
        frame.set_draw_handler(self.draw)
        frame.set_keydown_handler(self.keydown)
        frame.set_keyup_handler(self.keyup)
        time_interval = 1000.0
        timer = simplegui.create_timer(time_interval, self.rock_spawner)
        frame.set_mouseclick_handler(self.click)

        timer.start()
        frame.start()
Exemplo n.º 26
0
def main():
    # initialize stuff
    frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)
    
    # register handlers
    frame.set_keyup_handler(keyup)
    frame.set_keydown_handler(keydown)
    frame.set_mouseclick_handler(click)
    frame.set_draw_handler(draw)
    
    timer1 = simplegui.create_timer(1000.0, rock_spawner)
    timer2 = simplegui.create_timer(1000.0, ship_spawner)
    
    # get things rolling
    timer1.start()
    timer2.start()
    frame.start()
    
    # start game
    new_game()
def reset():
    global timer
    global tick
    global is_stop
    global attempt
    global success
    tick = 0
    timer.stop()
    attempt = 0
    success = 0
    is_stop = True
    timer = simplegui.create_timer(100, timer_handler)
def set_unload_handler(frame, handler, period = 1000):
    def unload_check():
        #credit: Michael Cimino for set_unload_handler
        try: 
            textwidth = frame.get_canvas_textwidth("t",12)
        except:
            textwidth = 0
        if textwidth==0:
            unloaded_check_timer.stop()
            handler()
    unloaded_check_timer = simplegui.create_timer(period, unload_check)
    unloaded_check_timer.start()
def keydown_handler(key):
    global angle_accel, angle_accel_timer, thrusting, is_pressing_left, is_pressing_right 
    angle_accel_val = 0.008
    if key == simplegui.KEY_MAP['left']:
        angle_accel = -angle_accel_val
        if angle_accel_timer:
            angle_accel_timer.stop()
        angle_accel_timer = simplegui.create_timer( ( 1000 / 60), spin_ship)
        my_ship.angle_vel = 0
        angle_accel_timer.start()
        is_pressing_left = True
    elif key == simplegui.KEY_MAP['right']:
        angle_accel = angle_accel_val
        if angle_accel_timer:
            angle_accel_timer.stop()
        angle_accel_timer = simplegui.create_timer( ( 1000 / 60), spin_ship)
        my_ship.angle_vel = 0
        angle_accel_timer.start()
        is_pressing_right = True
    elif key == simplegui.KEY_MAP['up']:
        my_ship.set_thrust(True)
    elif key == simplegui.KEY_MAP['space']:
        my_ship.shoot()
Exemplo n.º 30
0
def start():
    """
    Start the game.
    """
    global timer

    if SIMPLEGUICS2PYGAME:
        frame._set_canvas_background_image(loader.get_image('nebula'))

    frame.set_draw_handler(draw)

    timer = simplegui.create_timer(1000, rock_spawner)
    timer.start()
    rock_spawner()
Exemplo n.º 31
0
# determine if the group of missiles collide with the group of rocks
# return the number of collisions, so we can increment the score
def group_group_collide(group,other_group):
    remove_set = set()
    for element in group:
        if (group_collide(other_group,element)):
            remove_set.add(element)
    group.difference_update(remove_set)
    return (len(remove_set))

# initialize stuff
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)

# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
#a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, .1, asteroid_image, asteroid_info)
a_missile = Sprite([2 * WIDTH / 3, 2 * HEIGHT / 3], [-1,1], 0, 0, missile_image, missile_info, missile_sound)


# register handlers
frame.set_keyup_handler(keyup)
frame.set_keydown_handler(keydown)
frame.set_mouseclick_handler(click)
frame.set_draw_handler(draw)

timer = simplegui.create_timer(ROCK_SPAWN_TIME, rock_spawner)

# get things rolling
timer.start()
frame.start()
Exemplo n.º 32
0
                rock_vel[1] += 10 * rock_vel[1]
            elif score > 300:
                rock_vel[0] += 20 * rock_vel[0]
                rock_vel[1] += 20 * rock_vel[1]
            rock_avel = random.random() * .2 - .1
            a_rock = Sprite(rock_pos, rock_vel, 0, rock_avel, asteroid_image,
                            asteroid_info)
            if dist(rock_pos, my_ship.pos) > 2 * my_ship.radius:
                rock_group.add(a_rock)


# initialize stuff
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)

# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
rock_group = set([])
missile_group = set([])

# register handlers
frame.set_keyup_handler(keyup)
frame.set_keydown_handler(keydown)
frame.set_mouseclick_handler(click)
frame.set_draw_handler(draw)

timer = simplegui.create_timer(1000.0, rock_spawner)

# get things rolling
timer.start()
frame.start()
reset()
Exemplo n.º 33
0
def keyup_handler(key):
    my_ship.thrust = False
    my_ship.rot = 0
    my_ship.missile = False
    ship_thrust_sound.rewind()
    #missile_sound.rewind()


# initialize frame
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)

# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, 0.03, ship_image, ship_info,
               flame_info)
## my_ship=Ship(initial position, initial velocity, initial angle, fricition, ship image, no flame info, flame info)
a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, 0, asteroid_image,
                asteroid_info)
a_missile = Sprite([2 * WIDTH / 3, 2 * HEIGHT / 3], [-1, 1], 0, 0,
                   missile_image, missile_info, missile_sound)

# register handlers
frame.set_draw_handler(draw)
frame.set_keydown_handler(keydown_handler)
frame.set_keyup_handler(keyup_handler)
timer = simplegui.create_timer(interval, rock_spawner)

# get things rolling
timer.start()
frame.start()
Exemplo n.º 34
0
    canvas.draw_circle([WIDTH / 2, HEIGHT / 2], radius**1.5, 5, "yellow")
    canvas.draw_circle([WIDTH / 2, HEIGHT / 2], radius**1.2, 1, "white")

    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius, 2, "red")
    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius**2, 2, "blue")
    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius**1.75, 3, "pink")
    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius**0.5, 8, "green")
    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius**1.5, 4, "yellow")
    canvas.draw_circle([WIDTH / 3, HEIGHT / 2], radius**1.2, 1.5, "white")

    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius, 1, "red")
    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius**2, 2, "blue")
    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius**1.75, 3, "pink")
    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius**0.5, 8, "green")
    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius**1.5, 5, "yellow")
    canvas.draw_circle([WIDTH / 1.5, HEIGHT / 2], radius**1.2, 2, "white")

    canvas.draw_circle([WIDTH / 2, HEIGHT / 2], radius**1.4, 3, "orange")


# Create frame and timer

f = simplegui.create_frame("Radius", WIDTH, HEIGHT, 60)
t = simplegui.create_timer(100, tradius)

f.set_draw_handler(draw)

# Start timer

f.start()
t.start()
Exemplo n.º 35
0
def background_timer_handler():
    global Color_Counter_Background_Background
    global Current_Color_Background
    global Counter_Background
    global Color_Rainbow
    if Rainbow_Toggle == True:
        if Color_Counter_Background_Background < 6:
            Color_Counter_Background_Background = Color_Counter_Background_Background + 1
        else:
            Color_Counter_Background_Background = 0
    Current_Color_Background = Color_Rainbow[
        Color_Counter_Background_Background]
    frame.set_canvas_background(Current_Color_Background)


timer = simplegui.create_timer(background_timer_interval,
                               background_timer_handler)
timer.start()
background_timer_handler()


def time_text_handler():
    global Color_Counter_Text
    global Current_Color_Text
    global Counter_Background
    global Color_Rainbow
    global Current_Color_Text
    global Color_Counter_Text
    if Rainbow_Toggle == True:
        if Color_Counter_Text < 6:
            Color_Counter_Text = Color_Counter_Text + 1
        else:
Exemplo n.º 36
0
        else:
            paddle_northwest_point = frame_size[1] - paddle_height
    else:
        pass


def ball_tick():
    """define ball movement based on timer"""
    global ball_pos, ball_time, ball_shift_size
    ball_time += 1
    if ball_time % 100 == 0:
        ball_shift_size += 5
    ball_pos = add_vector(ball_pos,
                          multiply_vector(ball_vector, ball_shift_size))
    ball_collision()
    ball_reflection()


# define frame
frame = simplegui.create_frame("Pong", frame_size[0], frame_size[1])
paddle_timer = simplegui.create_timer(100, paddle_tick)
ball_timer = simplegui.create_timer(200, ball_tick)

# register handler functions
frame.set_draw_handler(draw)
frame.set_keydown_handler(paddle_shift)
frame.set_keyup_handler(stop_paddle_shift)

# start frame
frame.start()
ball_timer.start()
def func_reset():

    timer.stop()
    global t, s1, s2, m, p, x, y, z
    t = 0
    s1 = 0
    s2 = 0
    m = 0
    p = str(m) + ":" + str(s1) + str(s2) + "." + str(t)
    x = 0
    y = 0
    z = str(y) + "/" + str(x)


# define event handler for timer with 0.1 sec interval
timer = simplegui.create_timer(100, format)

# define draw handler


def draw_sthing(canvas):
    global p, z
    canvas.draw_text(str(p), [100, 100], 50, "White")
    canvas.draw_text(str(z), [200, 30], 40, "Green")


# create frame

frame = simplegui.create_frame("Stopwatch", 300, 200)

# register event handlers
Exemplo n.º 38
0
def start():
    # Start the frame animation
    frame.start()
    timer = simplegui.create_timer(250, actualize)
    frame.set_keydown_handler(keyDown)
    timer.start()
    flag = 1


def stop():
    global flag, attempts, score
    flag = 0
    if (second % 5 == 0):
        attempts += 1
        score += 1
    else:
        attempts += 1


def reset():
    global flag, val, minute, second, tempSec, milisec
    val = "0.00.0"
    flag = 0
    minute = second = milisec = 0
    tempSec = "00"


frame = simplegui.create_frame("StopWatch", 300, 300)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(100, convert)
frame.add_button("Start", start, 50)
frame.add_button("Stop", stop, 50)
frame.add_button("Reset", reset, 50)

frame.start()
timer.start()
Exemplo n.º 40
0
            or (max_test_images_loaded <= 0)):
        timer.stop()
        frame.set_draw_handler(draw)

    max_test_images_loaded -= 1


# Main
if __name__ == '__main__':
    # Create frame
    frame = simplegui.create_frame('Blackjack', FRAME_WIDTH, FRAME_HEIGHT, 100)

    # Control panel
    frame.add_button('Deal', deal, 100)
    frame.add_label('')
    frame.add_button('Hit', hit, 100)
    frame.add_label('')
    frame.add_button('Stand', stand, 100)
    frame.add_label('')
    frame.add_label('')
    frame.add_button('Quit', frame.stop)

    # Register event handlers
    frame.set_draw_handler(draw_wait_images)

    timer = simplegui.create_timer(100, test_images_loaded)
    timer.start()
    test_images_loaded()

    frame.start()
Exemplo n.º 41
0

def timer_handler():
    global a, b, c, d
    d = d + 1
    if d == 10:
        d = 0
        global c
        c = c + 1
        if c == 10:
            c = 0
            global b
            if b == 6:
                b = 0
                global a
                a = a + 1


frame = simplegui.create_frame('Testing', 390, 300)
frame.set_canvas_background('Blue')
button1 = frame.add_button(
    'start',
    start,
    100,
)
button2 = frame.add_button('stop', stop, 100)
button3 = frame.add_button('restart', reset, 100)
frame.set_draw_handler(draw_handler)
timer = simplegui.create_timer(interval, timer_handler)
frame.start()
    global counter
    counter += 1


# define draw handler


def draw(canvas):
    canvas.draw_text(format(counter), (75, 120), 64, 'White')
    canvas.draw_text(str(wins) + "/" + str(stops), (240, 30), 30, 'White')


# create frame

frame = simplegui.create_frame("frame", 300, 200)
timer = simplegui.create_timer(100, time_handler)

# register event handlers

frame.set_draw_handler(draw)
label0 = frame.add_label('Stop the timer at 5 seconds intervals!')
label1 = frame.add_label('')
button1 = frame.add_button('Start', start, 100)
label2 = frame.add_label('')
button2 = frame.add_button("Stop", stop, 100)
label3 = frame.add_label('')
button3 = frame.add_button("Reset", reset, 100)

# start frame
frame.start()
Exemplo n.º 43
0
    count = 0
    stop = True
    total_stops = 0
    succes_stops = 0
    timer.stop()


def tick():
    global count
    count += 1


def draw(canvas):
    text = format(count)
    canvas.draw_text( text, (80, 125), 42, "white")
    canvas.draw_text(str(succes_stops) + '/' + str(total_stops), (190,30), 24, "pink")
    

frame = simplegui.create_frame("Stopwatch game", 250, 250)
frame.set_canvas_background('green')


frame.add_button("Start", Start, 100)
frame.add_button("Stop", Stop, 100)
frame.add_button("Reset", Reset, 100)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(interval, tick)


frame.start()
Reset()
Exemplo n.º 44
0
def score():
    global totalStops, goalStop
            
    return str(goalStop) + "/" + str(totalStops)

# timer and draw handlers
def tick():
    global seconds
    seconds = int(seconds)
    seconds = seconds + 1
    

def draw_handler(canvas):
    global seconds
    #seconds = str(seconds)
    canvas.draw_text((format(seconds)), (120, 150), 24, 'White')
    canvas.draw_text((score()), (250, 20), 20, 'White')
    
    
# create frame
frame = simplegui.create_frame("Timer", 300, 300)
timer = simplegui.create_timer(100, tick)
frame.set_draw_handler(draw_handler)
start = frame.add_button('Start', start_handler)
stop = frame.add_button('Stop', stop_handler)
reset = frame.add_button('Reset', reset_handler)


# start frame
frame.start()
Exemplo n.º 45
0
    x = random.randrange(0, width)
    y = random.randrange(0, height)
    position[0] = x
    position[1] = y

# Handler to draw on canvas
def draw(canvas):
    canvas.draw_text(message, position, 36, "Red")

# Create a frame
frame = simplegui.create_frame("Home", width, height)

# Register event handlers
text = frame.add_input("Message:", update, 150)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(interval, tick)

# Start the frame animation
frame.start()
timer.start()
--------------------------------------------------------------------
# Counter ticks

###################################################
# Student should add code where relevant to the following.

import simplegui

counter = 0

# Timer handler
# handlers
def draw(canvas):
    global x, y, change, message
    print x, y, change
    canvas.draw_text(message, (x, y), 30, "Red")


def toggle():
    global change
    if (change == False):
        change = True
    else:
        change = False


def update_message(txt):
    global message
    message = txt


# create frame
frame = simplegui.create_frame("screensaver", 500, 500)
toggle = frame.add_button("Toggle", toggle, 100)
input_txt = frame.add_input("message", update_message, 200)
timer = simplegui.create_timer(1000, changeCartetian)
frame.set_draw_handler(draw)

# register
frame.start()
timer.start()
Exemplo n.º 47
0
# define event handler for timer with 0.1 sec interval
def increment():
    global milliseconds
    milliseconds = milliseconds + 1


# define draw handler
def draw(canvas):
    global wins
    global total_attempts
    game = str(wins) + '/' + str(total_attempts)
    canvas.draw_text(format(milliseconds), [125, 100], 24, 'white')
    canvas.draw_text(game, [265, 15], 24, 'red')


# create frame
frame = simplegui.create_frame("StopWatch", 300, 200)

# register event handlers
frame.add_button("Start", start, 100)
frame.add_button("Stop", stop, 100)
frame.add_button("Restart", reset, 100)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(100, increment)

# start frame
frame.start()

# Please remember to review the grading rubric
Exemplo n.º 48
0
# define event handler for timer with 0.1 sec interval
def milli():
    global milliseconds

    milliseconds = milliseconds + 1

    #print milliseconds
    format(milliseconds)


# define draw handler
def curr_time(canvas):
    canvas.draw_text(str(current_time), (100, 150), 30, 'White')
    canvas.draw_text(str(score), (250, 35), 30, 'Green')


# create frame
frame = simplegui.create_frame("Stopwatch Game", 300, 300)
frame.set_draw_handler(curr_time)
button1 = frame.add_button('Start', start, 50)
button2 = frame.add_button('Stop', stop, 50)
button3 = frame.add_button('Reset', reset, 50)

# register event handlers
timer = simplegui.create_timer(100, milli)

# start frame
frame.start()

# Please remember to review the grading rubric
Exemplo n.º 49
0
                    main_list[(y * 3) + x] = turn_control['p']
                    if win_check(main_list, turn_control['p']) == False:
                        turn_change()
                        computer_AI()
                    else:
                        in_play = False


def new_game():
    global turn, turn_control, main_list, in_play
    timer.stop()
    main_list = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
    turn = random.choice(['p', 'c'])
    in_play = True
    if turn == 'p':
        turn_control['p'] = 'X'
        turn_control['c'] = 'O'
    else:
        turn_control['c'] = 'X'
        turn_control['p'] = 'O'
        computer_AI()


frame = simplegui.create_frame('Tic-Tac-Toe', width, height)
timer = simplegui.create_timer(500, new_game)
frame.add_button('New Game', new_game)
frame.set_mouseclick_handler(click)
frame.set_canvas_background('orange')
frame.set_draw_handler(draw)
frame.start()
Exemplo n.º 50
0

def keydown(key):
    global chag
    if key == simplegui.KEY_MAP["space"]:
        chag = [0, 0]


def draw(canvas):
    canvas.draw_polygon([[50, 50], [180, 50], [180, 140], [50, 140]],
                        line_width, 'Red')
    canvas.draw_circle(POS, radius, line_width, 'Green')


frame = simplegui.create_frame("Quiz4b, Q9", WIDTH, HEIGHT)
timer = simplegui.create_timer(t_interval, timer)
frame.set_keydown_handler(keydown)
frame.set_draw_handler(draw)

frame.start()
timer.start()

# Quiz 4b, Question 9
# http://www.codeskulptor.org/#user39_5PqX3jJTBCIXiLi_7.py

import simplegui

WIDTH = 200
HEIGHT = 100
var = 5
Exemplo n.º 51
0
    text_width = FRAME.get_canvas_textwidth(text, font_size)

    canvas.draw_text(text, ((CANVAS_WIDTH - text_width) // 2,
                            CANVAS_HEIGHT // 2 + font_size // 4), font_size,
                     'Green')


def stop_all():  # type: () -> None
    """Handler function to the Quit button."""
    TIMER.stop()
    SOUND.pause()
    FRAME.stop()


# Main
SOUND = simplegui.load_sound(
    'http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg'
)  # noqa
SOUND.play()

FRAME = simplegui.create_frame('Stop example', CANVAS_WIDTH, CANVAS_HEIGHT)

FRAME.add_button('Quit', stop_all)

FRAME.set_draw_handler(draw)

TIMER = simplegui.create_timer(1000, click)
TIMER.start()

FRAME.start()
Exemplo n.º 52
0

def up(key):
    if key in CLCK_WISE.keys():
        my_ship.change_angle_vel(CLCK_WISE[key], False)
    if key == simplegui.KEY_MAP["up"]:
        my_ship.thrust_switch()


# initialize frame
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)

# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, 0, asteroid_image,
                asteroid_info)
a_missile = Sprite([-10, -10], [0, 0], my_ship.angle, 0, missile_image,
                   missile_info, missile_sound)

# register handlers
frame.set_draw_handler(draw)
frame.set_keydown_handler(down)
frame.set_keyup_handler(up)

timer = simplegui.create_timer(1000.0, rock_spawner)
sound = simplegui.create_timer(25000.0, sound_restart)

# get things rolling
timer.start()
frame.start()
Exemplo n.º 53
0
        current_map[y][x] = MAP_TILE
    elif lastUpdated == 3:  # distructable
        current_map[y][x] = DISTRUCTABLE_TILE
    elif lastUpdated == 4:  # indistructable
        current_map[y][x] = UNDISTRUCTABLE_TILE


# Create a frame and assign callbacks to event handlers
frame = simplegui.create_frame('Bomberman : ' + VER, SCREEN_WIDTH,
                               SCREEN_HEIGHT)

frame.set_draw_handler(draw_handler)
frame.set_keydown_handler(keydown)
frame.set_mouseclick_handler(mouse_handler)

leTimer = simplegui.create_timer(TIMER_INTERVAL, moving_objects)
leTimer.start()

button1 = frame.add_button('Inc Speed', button_speed, 150)
label1 = frame.add_label('Speed = 1')
button2 = frame.add_button('Dec Speed', button_speedd, 150)

label11 = frame.add_label(' ')

button3 = frame.add_button('Inc Fire Range', button_fire, 150)
label2 = frame.add_label('Fire = 1')
button4 = frame.add_button('Dec Fire Range', button_fired, 150)

label12 = frame.add_label(' ')

button5 = frame.add_button('Inc Bomb Number', button_bombs, 150)
Exemplo n.º 54
0
    global t
    t += 1


def t3_h():
    global t
    while t != 0:
        t -= 1


def d_h(canvas):
    canvas.draw_circle(b_p, 5, 1, "red", "white")


def r_h():
    v[0] = 0
    v[1] = 0
    b_p[0] = 200
    b_p[1] = 200


frame1 = simplegui.create_frame("velocity program", 400, 400)
frame1.set_draw_handler(d_h)
frame1.add_button("reset", r_h)
frame1.set_keydown_handler(kd_h)
frame1.set_keyup_handler(ku_h)
timer1 = simplegui.create_timer(10, t_h)
timer2 = simplegui.create_timer(1000, t2_h)
timer3 = simplegui.create_timer(100, t3_h)
frame1.start()
timer1.start()
Exemplo n.º 55
0
        "Timer 1:     " + str(counter1[0] % 10) + "." + str(counter1[1]),
        [50, 100], 24, "White")
    canvas.draw_text(
        "Timer 2:     " + str(counter2[0] % 10) + "." + str(counter2[1]),
        [50, 200], 24, "White")


# Register event handlers.
frame = simplegui.create_frame("Mystery bug", 300, 300)
frame.add_button("Start timer1", start1, 200)
frame.add_button("Stop timer1", stop1, 200)
frame.add_button("Start timer2", start2, 200)
frame.add_button("Stop timer2", stop2, 200)
frame.set_draw_handler(draw)

timer1 = simplegui.create_timer(100, tick1)
timer2 = simplegui.create_timer(100, tick2)

# Start frame.
frame.start()

# optional exercises 4 Practice for key events

# 1) debugging a program that uses key events

#imports
import simplegui

#globals
message = "Welcome!"
                        card[tick] = list_1[i * 4 + j]
                        card_index[tick] = i * 4 + j
                        tick += 1


def run():
    global rec_color, rec_color_code, count
    for i in range(0, 4):
        for j in range(0, 4):
            if rec_color_code[i * 4 + j] == 0 and count < 2:
                rec_color[i * 4 + j] = "red"
            elif rec_color_code[i * 4 + j] == 0 and count >= 2:
                rec_color_code[i * 4 + j] = 2
            elif rec_color_code[i * 4 + j] == 1:
                rec_color[i * 4 + j] = "green"
            else:
                rec_color[i * 4 + j] = "yellow"
                rec_color_code[i * 4 + j] = 2
    count += 1


frame = simplegui.create_frame("Memory", 200, 400)
frame.set_draw_handler(draw)
frame.set_mouseclick_handler(click)
frame.add_button("New Game", new_game, 150)
frame.add_label("Turns")
label = frame.add_label(str(turn))
timer = simplegui.create_timer(100, run)

frame.start()
timer.start()
Exemplo n.º 57
0
    """Change message on mouse click."""
    global message
    message = "Good job!"


def draw(canvas):
    """Draw message."""
    canvas.draw_text(message, [50, 112], 36, "Red")


# Create a frame and assign callbacks to event handlers

frame = simplegui.create_frame("Home", 300, 200)
frame.add_button("Click me", click)
frame.set_draw_handler(draw)

#####################
# Buggy code -- doesn't start timers


def timer1_handler():
    print "1"


def timer2_handler():
    print "2"


simplegui.create_timer(100, timer1_handler)
simplegui.create_timer(300, timer2_handler)