def wire_events(self): imp.IMP().add_delegate( events.UserEvent(CustomEvent.FIRST_CARD).listen( self.on_first_card)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.CARD_TABLE_RESIZED).listen( self.on_card_table_resized))
def __init__(self): pygame.init() self.island = maps.IslandMap((0, 0), imp.IMP().screen.size) self.outline = maps.LineMap((0, 0), imp.IMP().screen.size) imp.IMP().register(self.island) self.register([self.island]) self.wire_events()
def wire_events(self): imp.IMP().add_delegate( events.UserEvent(CustomEvent.CARD_MOTION).listen( self.on_card_motion, quell=True)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.CARD_DROPPED).listen( self.on_card_dropped))
def run(self): while imp.IMP().running: for event in pygame.event.get(): imp.IMP().dispatch(event) self.update() self.draw() self.free()
def wire_events(self): imp.IMP().add_listener(events.MouseLeftButtonDownEvent().create( self.on_mouse_left_button_down)) imp.IMP().add_listener(events.MouseLeftButtonUpEvent().create( self.on_mouse_left_button_up)) imp.IMP().add_listener(events.MouseMotionEvent().create( self.on_mouse_motion, quell=True))
def run(self): self.start() while imp.IMP().running: for event in pygame.event.get(): imp.IMP().on_event(event) self.game() self.draw() self.free()
def __init__(self): pygame.init() self.running = True self.size = App.WINDOW_SIZE self.surface = pygame.display.set_mode(self.size, pygame.RESIZABLE) self.text = geo.RenderText('Hello World!') self.rect = geo.Rect((10, 10), (20, 20), Color.RED) imp.IMP().register(self.text) imp.IMP().register(self.rect) imp.IMP().event_dispatcher = events.EventDispatcher() self.wire_events()
def run(self): try: while imp.IMP().running: for event in pygame.event.get(): imp.IMP().dispatch(event) self.update() self.draw() except Exception as ex: self.success = False print('Exception: {}'.format(ex)) traceback.print_exc() finally: self.free()
def on_card_layed(self, event): selected_card = event.card if not selected_card == None: max_area = 0 original_tile = selected_tile = self.card_tiles[ selected_card.tile_index] for tile in self.find_all(lambda x: not x == BlankTile.INDEX): if selected_card.rect.is_intersecting(tile.rect): area = selected_card.rect.intersecting( tile.rect).get_area() if area > max_area: max_area = area selected_tile = tile original_tile.pop() if not selected_tile.index == original_tile and selected_tile.can_lay( selected_card): self.post_score_update(selected_tile.index) print('Action> {} -> {} -> {}'.format(original_tile.index, selected_card, selected_tile)) selected_tile.lay(selected_card) undo_args = (original_tile, selected_tile, selected_card) undo_action = acts.UndoAction(self.undo_card_layed, self.redo_card_layed, *undo_args) imp.IMP().actions.post(undo_action) else: print('NonAction> {} <- {}'.format(original_tile, selected_card)) original_tile.lay(selected_card) if self.check_win(): events.UserEvent(CustomEvent.GAME_OVER).post()
def invoke(self, *args, **kargs): if imp.IMP().debug and not self.quell: print('Invoke -> {0}'.format(self.__str__())) ret_list = [] for m in self.invocation_list: ret_list.append(m(*args, **kargs)) return ret_list
def on_game_over(self, event): imp.IMP().actions.clear() self.stop_watch.stop() self.pause_text.set_text('Winner!') self.pause_text.center_on(self.center) self.pause_btn.set_enabled(False) self.pause()
def __init__(self): pygame.init() size = imp.IMP().screen.size self.island = maps.IslandMap((0, 0), size, 300, (10, 10)) self.line_map = maps.LineMap((0, 0), size, 300) self.register([self.island, self.line_map]) self.wire_events()
def draw(self): screen = imp.IMP().screen screen.fill(Color.TEAL_FELT) self.card_table.draw(screen.surface) self.pause_text.draw(screen.surface) self.left_side_bar.draw(screen.surface) self.right_side_bar.draw(screen.surface) screen.flip()
def __init__(self): self.seed = -1 self.deck = [] self.active_cards = [] self.shuffler = fs.Shuffler() self.winnable_hands = False self.deal_order = imp.IMP().config.try_get('NEW_DEAL', []) self.wire_events()
def get_style(self, key): postfix = '' if self.is_enabled: postfix = 'enabled' else: postfix = 'disabled' return imp.IMP().styles.try_get('{}_{}'.format(key, postfix), style.Style())
def __init__(self, left_top, size): self.click_time = 0 self.tile_info = {} self.card_tiles = [] self.mouse_clicks = [] self.mouse_unclicks = [] self.mw, self.mh = self.margins self.tile_width, self.tile_height = self.tile_size = (0, 0) self.rows = imp.IMP().config.try_get('GRID_ROWS', 0) self.cols = imp.IMP().config.try_get('GRID_COLS', 0) self.card_size_ratio = imp.IMP().config.try_get( 'CARD_SIZE_RATIO', 0.0).solution self.deck = Deck() self.parse_tiles() self.fill(*left_top, *size) self.set_size(size) self.set_position(left_top) self.wire_events()
def __init__(self): pygame.init() self.running = True self.size = App.WINDOW_SIZE self.surface = pygame.display.set_mode(self.size, pygame.RESIZABLE) self.event_manager = events.EventManager(is_debug=True) self.imp = imp.IMP().init(None, self.event_manager, True) self.register_objs() self.wire_events()
def assay_position(self): window_w, window_h = imp.IMP().screen.size #WindowSide.LEFT and WindowSide.TOP left, top = 0, 0 if self.window_side == WindowSide.RIGHT: left = window_w - self.w elif self.window_side == WindowSide.BOTTOM: top = window_h - self.h return (left, top)
def __init__(self): pygame.init() self.w, self.h = self.size = imp.IMP().screen.size self.elapsed = 1 self.is_win = False self.previous = None self.is_paused = True self.SEC_PER_FRAME = 1 / 60 self.center = tuple(x // 2 for x in self.size) self.title = imp.IMP().config.try_get('GAME_NAME', 'Default Name') self.card_table = cards.CardTable( (0, 0), self.size, margins=imp.IMP().config.try_get('CARD_TABLE_MARGINS', (0, 0))) self.pause_text = go.RenderText('Paused!', font_info=go.FontInfo(60, Color.BLUE), is_visible=False) self.pause_text.center_on(self.center) self.create_side_bars() self.wire_events() self.set_title()
def on_draw_one(self, event): if len(self.active_cards) < len(self.deck): next_index = len(self.active_cards) next_card = self.deck[next_index] self.active_cards.append(next_index) event.discard_tile.lay(next_card) self.update_remaining(event.deck_tile) events.UserEvent(CustomEvent.UPDATE_SCORE).post(inc=-1) print('Action> Next Card: (#{} {})'.format(next_index, next_card)) undo_args = (next_index, next_card, event.deck_tile, event.discard_tile) undo_action = acts.UndoAction(self.undo_draw, self.redo_draw, *undo_args) imp.IMP().actions.post(undo_action)
def wire_events(self): imp.IMP().add_delegate(events.QuitEvent().listen(self.on_quit)) imp.IMP().add_delegate(events.WindowResizedEvent().listen( self.on_resize)) imp.IMP().add_delegate( events.KeyDownEvent(pygame.K_ESCAPE).listen(self.on_pause)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.GAME_OVER).listen(self.on_game_over)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.UNDO_STACK_CLEARED).listen( self.on_redo_undo_changed)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.REDO_STACK_CLEARED).listen( self.on_redo_undo_changed)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.UNDO_ENABLED).listen( self.on_redo_undo_changed)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.REDO_ENABLED).listen( self.on_redo_undo_changed)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.UPDATE_SCORE).listen( self.on_update_score))
def on_quick_lay(self, event): card = event.card tile = self.find_tile_to_lay(card) source_tile = self.card_tiles[card.tile_index] if not tile == None: source_tile.pop() tile.lay(card) if not tile.index == source_tile.index: self.post_score_update(tile.index) print('Action> {} -> {} -> {}'.format(source_tile.index, card, tile)) undo_args = (source_tile, tile, card) undo_action = acts.UndoAction(self.undo_card_layed, self.redo_card_layed, *undo_args) imp.IMP().actions.post(undo_action) else: print('NonAction> {} <- {}'.format(source_tile, card)) if self.check_win(): events.UserEvent(CustomEvent.GAME_OVER).post()
def wire_events(self): imp.IMP().add_delegate(events.WindowResizedEvent().listen( self.on_resize)) imp.IMP().add_delegate(events.MouseMotionEvent().listen( self.on_mouse_motion, quell=True)) imp.IMP().add_delegate(events.MouseLeftButtonDownEvent().listen( self.on_mouse_left_button_down)) imp.IMP().add_delegate(events.MouseLeftButtonUpEvent().listen( self.on_mouse_left_button_up)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.QUICK_LAY).listen(self.on_quick_lay)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.CARD_LAYED).listen( self.on_card_layed))
def wire_events(self): imp.IMP().add_delegate( events.UserEvent(CustomEvent.TILE_CLICKED).listen( self.on_tile_clicked)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.TILE_DBL_CLICKED).listen( self.on_tile_dbl_clicked)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.NEW_DEAL).listen(self.on_new_deal)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.RESTART).listen(self.on_restart)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.DRAW_ONE).listen(self.on_draw_one)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.CARD_TABLE_RESIZED).listen( self.on_card_table_resized)) imp.IMP().add_delegate( events.UserEvent(CustomEvent.WINNABLE_HANDS).listen( self.on_winnable_hands))
def wire_events(self): imp.IMP().add_delegate(events.WindowResizedEvent().listen( self.on_resize))
def draw(self): imp.IMP().screen.fill(Color.TEAL_FELT) imp.IMP().draw() imp.IMP().screen.flip()
def update(self): imp.IMP().update()
def register(self, objects): for obj in objects: imp.IMP().register(obj)
def __init__(self, debug=True, window_size=WINDOW_SIZE): pygame.init() self.success = True imp.IMP().init(Screen(window_size), None, events.EventDispatcher(), debug)
def wire_events(self): imp.IMP().add_listener(events.WindowResizedEvent().create( self.on_resize))