Esempio n. 1
0
    def get_event(self, event, scale):
        if event.type == pygame.MOUSEMOTION:
            self.handle_motion(tools.scaled_mouse_pos(scale))

        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                self.handle_click(True, pos)

        elif event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                self.handle_click(False, pos)
Esempio n. 2
0
    def get_event(self, event, scale):
        if event.type == pygame.MOUSEMOTION:
            self.handle_motion(tools.scaled_mouse_pos(scale))

        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                self.handle_click(True, pos)

        elif event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                self.handle_click(False, pos)
Esempio n. 3
0
    def get_event(self, event, scale=(1, 1)):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.goto_lobby()
                return

            if event.key == pg.K_SPACE:
                self.playfield.depress_plunger()

            elif event.key == pg.K_f:
                self.fill_tray()

            elif event.key == pg.K_a:
                self.toggle_autoplay()

        elif event.type == pg.KEYUP:
            if event.key == pg.K_SPACE:
                self.playfield.release_plunger()

        if event.type == pg.MOUSEMOTION:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                sprite.pressed = sprite.rect.collidepoint(pos)

            for sprite in self.hud.sprites():
                if hasattr(sprite, 'on_mouse_enter'):
                    if sprite.rect.collidepoint(pos):
                        sprite.on_mouse_enter(pos)

                elif hasattr(sprite, 'on_mouse_leave'):
                    if not sprite.rect.collidepoint(pos):
                        sprite.on_mouse_leave(pos)

        elif event.type == pg.MOUSEBUTTONDOWN:
            pos = tools.scaled_mouse_pos(scale)
            for sprite in self.hud.sprites():
                if hasattr(sprite, 'on_mouse_click'):
                    if sprite.rect.collidepoint(pos):
                        sprite.pressed = True
                        self._clicked_sprite = sprite

        elif event.type == pg.MOUSEBUTTONUP:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                if sprite.rect.collidepoint(pos):
                    sprite.pressed = False
                    sprite.on_mouse_click(pos)
                self._clicked_sprite = None
Esempio n. 4
0
    def get_event(self, event, scale=(1, 1)):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.goto_lobby()
                return

            if event.key == pg.K_SPACE:
                self.playfield.depress_plunger()

            elif event.key == pg.K_f:
                self.fill_tray()

            elif event.key == pg.K_a:
                self.toggle_autoplay()

        elif event.type == pg.KEYUP:
            if event.key == pg.K_SPACE:
                self.playfield.release_plunger()

        if event.type == pg.MOUSEMOTION:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                sprite.pressed = sprite.rect.collidepoint(pos)

            for sprite in self.hud.sprites():
                if hasattr(sprite, 'on_mouse_enter'):
                    if sprite.rect.collidepoint(pos):
                        sprite.on_mouse_enter(pos)

                elif hasattr(sprite, 'on_mouse_leave'):
                    if not sprite.rect.collidepoint(pos):
                        sprite.on_mouse_leave(pos)

        elif event.type == pg.MOUSEBUTTONDOWN:
            pos = tools.scaled_mouse_pos(scale)
            for sprite in self.hud.sprites():
                if hasattr(sprite, 'on_mouse_click'):
                    if sprite.rect.collidepoint(pos):
                        sprite.pressed = True
                        self._clicked_sprite = sprite

        elif event.type == pg.MOUSEBUTTONUP:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                if sprite.rect.collidepoint(pos):
                    sprite.pressed = False
                    sprite.on_mouse_click(pos)
                self._clicked_sprite = None
Esempio n. 5
0
 def get_event(self, event, scale=(1,1)):
     """Check for events"""
     super(Bingo, self).get_event(event, scale)
     self.lobby_button.get_event(event)
     self.new_game_button.get_event(event)
     #
     if event.type == pg.QUIT:
         if prepare.ARGS['straight']:
             pg.quit()
             sys.exit()
         else:
             self.done = True
             self.next = "lobby"
     elif event.type in (pg.MOUSEBUTTONDOWN, pg.MOUSEMOTION):
         #
         self.ui.process_events(event, scale)
         self.bonus_buttons.process_events(event, scale)
         #
         pos = tools.scaled_mouse_pos(scale, event.pos)
     elif event.type == pg.KEYUP:
         if event.key == pg.K_ESCAPE:
             self.done = True
             self.next = "lobby"
         elif event.key == pg.K_SPACE:
             self.next_chip(None, None)
         elif event.key == pg.K_m:
             #self.persist["music_handler"].mute_unmute_music()
             self.sound_muted = not self.sound_muted
         elif event.key == pg.K_f:
             for card in self.cards:
                 self.add_generator('flash-labels', card.flash_labels())
Esempio n. 6
0
 def get_event(self, event, scale=(1, 1)):
     """Check for events"""
     super(Bingo, self).get_event(event, scale)
     self.lobby_button.get_event(event)
     self.new_game_button.get_event(event)
     #
     if event.type == pg.QUIT:
         if prepare.ARGS['straight']:
             pg.quit()
             sys.exit()
         else:
             self.done = True
             self.next = "lobby"
     elif event.type in (pg.MOUSEBUTTONDOWN, pg.MOUSEMOTION):
         #
         self.ui.process_events(event, scale)
         self.bonus_buttons.process_events(event, scale)
         #
         pos = tools.scaled_mouse_pos(scale, event.pos)
     elif event.type == pg.KEYUP:
         if event.key == pg.K_ESCAPE:
             self.done = True
             self.next = "lobby"
         elif event.key == pg.K_SPACE:
             self.next_chip(None, None)
         elif event.key == pg.K_m:
             #self.persist["music_handler"].mute_unmute_music()
             self.sound_muted = not self.sound_muted
         elif event.key == pg.K_f:
             for card in self.cards:
                 self.add_generator('flash-labels', card.flash_labels())
Esempio n. 7
0
    def get_event(self, event, scale=(1, 1)):
        """This method will be called for each event in the event queue
        while the state is active.
        """
        if event.type == pg.QUIT and not self.alert:
            self.done = True
            self.next = "lobby"
        elif event.type == pg.MOUSEBUTTONDOWN and not self.alert:
            #Use tools.scaled_mouse_pos(scale, event.pos) for correct mouse
            #position relative to the pygame window size.
            event_pos = tools.scaled_mouse_pos(scale, event.pos)
            log.info(event_pos)  #[for debugging positional items]

            for action in self.actions.values():
                action.execute(event_pos)

            self.keno_card.update(event_pos)

            spot_count = self.keno_card.spot_count
            if spot_count != self.prev_spot_count:
                self.pay_table.update(spot_count, self.pot._balance)
                self.prev_spot_count = spot_count

        if not self.alert:
            self.buttons.get_event(event)
        self.alert and self.alert.get_event(event)
Esempio n. 8
0
    def get_event(self, event, scale=(1,1)):
        """This method will be called for each event in the event queue
        while the state is active.
        """
        if event.type == pg.QUIT and not self.alert:
            self.done = True
            self.next = "lobby"
        elif event.type == pg.MOUSEBUTTONDOWN and not self.alert:
            #Use tools.scaled_mouse_pos(scale, event.pos) for correct mouse
            #position relative to the pygame window size.
            event_pos = tools.scaled_mouse_pos(scale, event.pos)
            log.info(event_pos) #[for debugging positional items]

            for action in self.actions.values():
                action.execute(event_pos)

            self.keno_card.update(event_pos)

            spot_count = self.keno_card.spot_count
            if spot_count != self.prev_spot_count:
                self.pay_table.update(spot_count, self.pot._balance)
                self.prev_spot_count = spot_count

        if not self.alert:
            self.buttons.get_event(event)
        self.alert and self.alert.get_event(event)
Esempio n. 9
0
    def get_event(self, event, scale=(1, 1)):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.goto_lobby()
                return

        if event.type == pg.MOUSEMOTION:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                sprite.pressed = sprite.rect.collidepoint(pos)

            for sprite in self.hud.sprites():
                if self._hovered_sprite is None:
                    if hasattr(sprite, 'on_mouse_enter'):
                        if sprite.rect.collidepoint(pos):
                            self._hovered_sprite = sprite
                            sprite.on_mouse_enter(pos)

                elif sprite is self._hovered_sprite:
                    if hasattr(sprite, 'on_mouse_leave'):
                        if not sprite.rect.collidepoint(pos):
                            self._hovered_sprite = None
                            sprite.on_mouse_leave(pos)

        elif event.type == pg.MOUSEBUTTONDOWN:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                for sprite in self.hud.sprites():
                    if hasattr(sprite, 'on_mouse_click'):
                        if sprite.rect.collidepoint(pos):
                            sprite.pressed = True
                            self._clicked_sprite = sprite

        elif event.type == pg.MOUSEBUTTONUP:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                if sprite.rect.collidepoint(pos):
                    sprite.pressed = False
                    sprite.on_mouse_click(pos)
                self._clicked_sprite = None

        if self._enable_chips:
            self.player_chips.get_event(event, scale)
            for bet in self.bets.groups():
                bet.get_event(event, scale)
Esempio n. 10
0
    def get_event(self, event, scale=(1, 1)):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.goto_lobby()
                return

        if event.type == pg.MOUSEMOTION:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                sprite.pressed = sprite.rect.collidepoint(pos)

            for sprite in self.hud.sprites():
                if self._hovered_sprite is None:
                    if hasattr(sprite, 'on_mouse_enter'):
                        if sprite.rect.collidepoint(pos):
                            self._hovered_sprite = sprite
                            sprite.on_mouse_enter(pos)

                elif sprite is self._hovered_sprite:
                    if hasattr(sprite, 'on_mouse_leave'):
                        if not sprite.rect.collidepoint(pos):
                            self._hovered_sprite = None
                            sprite.on_mouse_leave(pos)

        elif event.type == pg.MOUSEBUTTONDOWN:
            if event.button == 1:
                pos = tools.scaled_mouse_pos(scale)
                for sprite in self.hud.sprites():
                    if hasattr(sprite, 'on_mouse_click'):
                        if sprite.rect.collidepoint(pos):
                            sprite.pressed = True
                            self._clicked_sprite = sprite

        elif event.type == pg.MOUSEBUTTONUP:
            pos = tools.scaled_mouse_pos(scale)
            sprite = self._clicked_sprite
            if sprite is not None:
                if sprite.rect.collidepoint(pos):
                    sprite.pressed = False
                    sprite.on_mouse_click(pos)
                self._clicked_sprite = None

        if self._enable_chips:
            self.player_chips.get_event(event, scale)
            for bet in self.bets.groups():
                bet.get_event(event, scale)
Esempio n. 11
0
 def get_event(self, event, scale):
     self.textbox.get_event(event, tools.scaled_mouse_pos(scale))
     self.buttons.get_event(event)
     if event.type == pg.QUIT:
         self.back_to_menu()
     elif event.type == pg.KEYUP:
         if event.key == pg.K_ESCAPE:
             self.back_to_menu()
Esempio n. 12
0
 def get_event(self, event, scale):
     self.textbox.get_event(event, tools.scaled_mouse_pos(scale))
     self.buttons.get_event(event)
     if event.type == pg.QUIT:
         self.back_to_menu()
     elif event.type == pg.KEYUP:
         if event.key == pg.K_ESCAPE:
             self.back_to_menu()
Esempio n. 13
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         self.timer += dt
         if self.current_player is not self.game.player:
             if self.timer > self.time_limit:
                 self.done = True
         self.player_buttons.update(mouse_pos)
Esempio n. 14
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         self.timer += dt
         if self.current_player is not self.game.player:
             if self.timer > self.time_limit:
                 self.done = True
         self.player_buttons.update(mouse_pos)
Esempio n. 15
0
 def get_event(self, event, scale=(1,1)):
     if event.type == pg.QUIT:
         #self.cash_out_player()
         self.done = True
         self.next = "lobby"
     elif event.type == pg.VIDEORESIZE:
         self.set_table()
     self.buttons.get_event(event)
     for widget in self.widgets:
         widget.get_event(event, tools.scaled_mouse_pos(scale))
Esempio n. 16
0
 def get_event(self, event, scale=(1, 1)):
     if event.type == pg.QUIT:
         #self.cash_out_player()
         self.done = True
         self.next = "lobby"
     elif event.type == pg.VIDEORESIZE:
         self.set_table()
     self.buttons.get_event(event)
     for widget in self.widgets:
         widget.get_event(event, tools.scaled_mouse_pos(scale))
Esempio n. 17
0
    def update(self, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.general_update(dt, mouse_pos)

        if not self.animations:
            self.done = True
            self.next = "Dealing"
        for label in self.labels:
            label.image.set_alpha(self.alpha)
        self.big_label.image.set_alpha(self.big_alpha)
Esempio n. 18
0
    def update(self, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.general_update(dt, mouse_pos)

        if not self.animations:
            self.done = True
            self.next = "Dealing"
        for label in self.labels:
            label.image.set_alpha(self.alpha)
        self.big_label.image.set_alpha(self.big_alpha)
Esempio n. 19
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         if self.label:
             self.label.image.set_alpha(self.label.alpha)
             if self.label.alpha <= 0:
                 self.next_label()
         else:
             self.done = True
Esempio n. 20
0
    def get_event(self, event, scale):
        self.game.get_event(event)
        if event.type == pg.QUIT:
            self.back_to_lobby()
        elif event.type == pg.MOUSEBUTTONDOWN:
            pos = tools.scaled_mouse_pos(scale, event.pos)
            if not self.game.moving_stacks and event.button == 1:
                new_movers = self.game.player.chip_pile.grab_chips(pos)
                self.last_click = pg.time.get_ticks()
                if new_movers:
                    self.play_chip_sound()
                    self.game.moving_stacks.append(new_movers)
                for hand in self.game.player.hands:
                    unbet_stack = hand.bet.grab_chips(pos)
                    if unbet_stack:
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(unbet_stack.chips)

        elif event.type == pg.MOUSEBUTTONUP:
            now = pg.time.get_ticks()
            span = now - self.last_click
            pos = tools.scaled_mouse_pos(scale, event.pos)
            if self.game.moving_stacks and event.button == 1:
                for stack in self.game.moving_stacks:
                    stack.rect.bottomleft = pos
                    if self.game.chip_rack.rect.collidepoint(pos):
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(
                            self.game.chip_rack.break_chips(stack.chips))
                    elif span > 300 and self.game.player.chip_pile.rect.collidepoint(
                            pos):
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(stack.chips)
                    else:
                        self.play_chip_sound()
                        self.game.current_player_hand.bet.add_chips(
                            stack.chips)
                self.game.moving_stacks = []
        if self.window:
            self.window.get_event(event)
        else:
            self.lobby_button.get_event(event)
            self.deal_button.get_event(event)
Esempio n. 21
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         if self.label:
             self.label.image.set_alpha(self.label.alpha)
             if self.label.alpha <= 0:
                 self.next_label()
         else:
             self.done = True
Esempio n. 22
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     for label in self.game.result_labels:
         label.update(dt)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.buttons.update(mouse_pos)
         self.lobby_button.update(mouse_pos)
Esempio n. 23
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     for label in self.game.result_labels:
         label.update(dt)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.buttons.update(mouse_pos)
         self.lobby_button.update(mouse_pos)
Esempio n. 24
0
    def get_event(self, event, scale):
        self.game.get_event(event)
        if event.type == pg.QUIT:
            self.back_to_lobby()
        elif event.type == pg.MOUSEBUTTONDOWN:
            pos = tools.scaled_mouse_pos(scale, event.pos)
            if not self.game.moving_stacks and event.button == 1:
                new_movers = self.game.player.chip_pile.grab_chips(pos)
                self.last_click = pg.time.get_ticks()
                if new_movers:
                    self.play_chip_sound()
                    self.game.moving_stacks.append(new_movers)
                for hand in self.game.player.hands:
                    unbet_stack = hand.bet.grab_chips(pos)
                    if unbet_stack:
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(unbet_stack.chips)

        elif event.type == pg.MOUSEBUTTONUP:
            now = pg.time.get_ticks()
            span = now - self.last_click
            pos = tools.scaled_mouse_pos(scale, event.pos)
            if self.game.moving_stacks and event.button == 1:
                for stack in self.game.moving_stacks:
                    stack.rect.bottomleft = pos
                    if self.game.chip_rack.rect.collidepoint(pos):
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(self.game.chip_rack.break_chips(stack.chips))
                    elif span > 300 and self.game.player.chip_pile.rect.collidepoint(pos):
                        self.play_chip_sound()
                        self.game.player.chip_pile.add_chips(stack.chips)
                    else:
                        self.play_chip_sound()
                        self.game.current_player_hand.bet.add_chips(stack.chips)
                self.game.moving_stacks = []
        if self.window:
            self.window.get_event(event)
        else:
            self.lobby_button.get_event(event)
            self.deal_button.get_event(event)
Esempio n. 25
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.buttons.update(mouse_pos)
        self.draw(surface)
        self.get_dice_total(current_time)
        self.set_point()

        for h in self.bets.keys():
            self.bets[h].update(mouse_pos, self.point)
        self.pointchip.update(current_time, self.dice_total, self.dice[0])
        self.update_total_label()
        for widget in self.widgets:
            widget.update()
Esempio n. 26
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.buttons.update(mouse_pos)
     self.scrollers.update(self.screen_rect, dt)
     if self.scrollers:
         if all(scroller.done for scroller in self.scrollers):
             self.scrollers.empty()
     else:
         self.marquees.update(dt)
         self.new_game.visible = True
         self.load_game.visible = self.controller.saved_stats_are_available
     self.lights.update(dt)
     self.draw(surface, dt)
Esempio n. 27
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.lobby_button.update(mouse_pos)
         self.animations.update(dt)
         if not self.animations:
             self.next = "Show Results"
             self.done = True
Esempio n. 28
0
 def update(self, surface, keys, current_time, dt, scale):
     if self.game:
         self.game.update(surface, keys, current_time, dt, scale)
         if self.game.done:
             self.game.cleanup()
             self.game = None
     else:
         mouse_pos = tools.scaled_mouse_pos(scale)
         self.chip_curtain.update(dt)
         self.buttons.update(mouse_pos)
         self.game_buttons.update(mouse_pos)
         self.animations.update(dt)
         self.draw(surface)
Esempio n. 29
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.buttons.update(mouse_pos)
        self.draw(surface)
        self.get_dice_total(current_time)
        self.set_point()

        for h in self.bets.keys():
            self.bets[h].update(mouse_pos, self.point)
        self.pointchip.update(current_time, self.dice_total, self.dice[0])
        self.update_total_label()
        for widget in self.widgets:
            widget.update()
Esempio n. 30
0
 def update(self, surface, keys, current_time, dt, scale):
     if self.game:
         self.game.update(surface, keys, current_time, dt, scale)
         if self.game.done:
             self.game.cleanup()
             self.game = None
     else:
         mouse_pos = tools.scaled_mouse_pos(scale)
         self.chip_curtain.update(dt)
         self.buttons.update(mouse_pos)
         self.game_buttons.update(mouse_pos)
         self.animations.update(dt)
         self.draw(surface)
Esempio n. 31
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.buttons.update(mouse_pos)
     self.scrollers.update(self.screen_rect, dt)
     if self.scrollers:
         if all(scroller.done for scroller in self.scrollers):
             self.scrollers.empty()
     else:
         self.marquees.update(dt)
         self.new_game.visible = True
         self.load_game.visible = self.controller.saved_stats_are_available
     self.lights.update(dt)
     self.draw(surface, dt)
Esempio n. 32
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.lobby_button.update(mouse_pos)
         self.animations.update(dt)
         if not self.animations:
             self.next = "Show Results"
             self.done = True
Esempio n. 33
0
    def update(self, surface, keys, current, dt, scale, player):
        self.buttons.update(tools.scaled_mouse_pos(scale))
        self.labels = []

        balance = "Account Balance: ${:.2f}".format(player.account.balance)
        self.labels.append(Label(self.font, 48, balance, "white", {"topleft": (200, 150)}))
        self.labels.append(Label(self.font, 36, "Menu", "white", {"midright": (1278 - 27, 840 + 32)}))
        top = 300
        for transaction, amount in player.account.transactions[::-1]:
            label1 = Label(self.font, 36, transaction, "white", {"topleft": (200, top)})
            label2 = Label(self.font, 36, "${:.2f}".format(amount), "white", {"topright": (1220, top)})
            self.labels.extend([label1, label2])
            top += label1.rect.height
        self.draw(surface)
Esempio n. 34
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     for blinker in self.game.result_labels:
         blinker.update(dt)
     self.animations.update(dt)
     for fader in self.fade_labels:
         fader.image.set_alpha(self.alpha)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.lobby_button.update(mouse_pos)
Esempio n. 35
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
     self.game.update(dt, mouse_pos)
     for blinker in self.game.result_labels:
         blinker.update(dt)
     self.animations.update(dt)
     for fader in self.fade_labels:
         fader.image.set_alpha(self.alpha)
     if self.window:
         self.window.update(mouse_pos)
         if self.window.done:
             self.window = None
     else:
         self.lobby_button.update(mouse_pos)
Esempio n. 36
0
    def get_event(self, event, scale):
        self.coins_button.get_event(event)
        self.cash_button.get_event(event)
        for button in self.main_buttons:
            button.get_event(event)
        if self.state == "WON":
            for button in self.yes_no_buttons:
                button.get_event(event)

        if event.type == pg.MOUSEBUTTONDOWN:
            if self.state == "PLAYING" or self.state == "DOUBLE UP":
                mouse_pos = tools.scaled_mouse_pos(scale)
                index = self.dealer.get_event(mouse_pos)
                if type(index) == int:
                    self.make_held(str(index))  # Little hack
Esempio n. 37
0
    def get_event(self, event, scale):
        self.coins_button.get_event(event)
        self.cash_button.get_event(event)
        for button in self.main_buttons:
            button.get_event(event)
        if self.state == "WON":
            for button in self.yes_no_buttons:
                button.get_event(event)

        if event.type == pg.MOUSEBUTTONDOWN:
            if self.state == "PLAYING" or self.state == "DOUBLE UP":
                mouse_pos = tools.scaled_mouse_pos(scale)
                index = self.dealer.get_event(mouse_pos)
                if type(index) == int:
                    self.make_held(str(index))  # Little hack
Esempio n. 38
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         for blinker in self.blinkers:
             blinker.update(dt)
         self.player_buttons.update(mouse_pos)
         self.fade_labels()
         if self.alpha < 1 and not self.toggled:
             self.toggle_buttons(True)
             self.toggled = True
             for text in self.advice_texts:
                 self.advisor.queue_text(text, dismiss_after=3500)
             if not self.free_ride:
                 self.lobby_button.call = self.back_to_lobby
Esempio n. 39
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     if not self.window:
         for blinker in self.blinkers:
             blinker.update(dt)
         self.player_buttons.update(mouse_pos)
         self.fade_labels()
         if self.alpha < 1 and not self.toggled:
             self.toggle_buttons(True)
             self.toggled = True
             for text in self.advice_texts:
                 self.advisor.queue_text(text, dismiss_after=3500)
             if not self.free_ride:
                 self.lobby_button.call = self.back_to_lobby
Esempio n. 40
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
        g = self.game
        g.update(dt, mouse_pos)

        self.split_button.active = False
        self.split_button.visible = False
        self.double_down_button.active = False
        self.double_down_button.visible = False

        hand = g.current_player_hand
        hand_score = hand.best_score()
        if hand_score is None:
            hand.busted = True
            hand.final = True
        chip_total = g.player.chip_pile.get_chip_total()
        bet = hand.bet.get_chip_total()

        if len(hand.cards) == 2 and len(g.player.hands) < 2:
            c1 = hand.card_values[hand.cards[0].value]
            c2 = hand.card_values[hand.cards[1].value]
            if c1 == c2 and chip_total >= bet:
                self.split_button.active = True
                self.split_button.visible = True
        if len(hand.cards) == 2:
            if hand_score == 21:
                hand.blackjack = True
                hand.final = True
            elif chip_total >= bet:
                self.double_down_button.active = True
                self.double_down_button.visible = True

        if hand.final:
            if all([hand.final for hand in g.player.hands]):
                if not self.animations:
                    g.dealer.hand.cards[0].face_up = True
                    self.next = "Dealer Turn"
                    self.done = True
            else:
                next_hand = [x for x in g.player.hands if not x.final][0]
                g.current_player_hand = next_hand
        if self.window:
            self.window.update(mouse_pos)
            if self.window.done:
                self.window = None
        else:
            self.buttons.update(mouse_pos)
            self.animations.update(dt)
Esempio n. 41
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
        g = self.game
        g.update(dt, mouse_pos)

        self.split_button.active = False
        self.split_button.visible = False
        self.double_down_button.active = False
        self.double_down_button.visible = False

        hand = g.current_player_hand
        hand_score = hand.best_score()
        if hand_score is None:
            hand.busted = True
            hand.final = True
        chip_total = g.player.chip_pile.get_chip_total()
        bet = hand.bet.get_chip_total()

        if len(hand.cards) == 2 and len(g.player.hands) < 2:
            c1 = hand.card_values[hand.cards[0].value]
            c2 = hand.card_values[hand.cards[1].value]
            if c1 == c2 and chip_total >= bet:
                self.split_button.active = True
                self.split_button.visible = True
        if len(hand.cards) == 2:
            if hand_score == 21:
                hand.blackjack = True
                hand.final = True
            elif chip_total >= bet:
                self.double_down_button.active = True
                self.double_down_button.visible = True

        if hand.final:
            if all([hand.final for hand in g.player.hands]):
                if not self.animations:
                    g.dealer.hand.cards[0].face_up = True
                    self.next = "Dealer Turn"
                    self.done = True
            else:
                next_hand = [x for x in g.player.hands if not x.final][0]
                g.current_player_hand = next_hand
        if self.window:
            self.window.update(mouse_pos)
            if self.window.done:
                self.window = None
        else:
            self.buttons.update(mouse_pos)
            self.animations.update(dt)
Esempio n. 42
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
        self.game.update(dt, mouse_pos)
        bets = [x.bet.get_chip_total() for x in self.game.player.hands]
        self.deal_button.visible = any(bets) and not self.game.moving_stacks

        if self.window:
            self.window.update(mouse_pos)
            if self.window.done:
                self.window = None
        else:
            self.lobby_button.update(mouse_pos)
            self.deal_button.update(mouse_pos)
        for stack in self.game.moving_stacks:
            x, y = mouse_pos
            stack.rect.bottomleft = (x - (self.game.chip_size[0] // 2), y + 6)
Esempio n. 43
0
    def update(self, surface, keys, current_time, dt, scale):
        mouse_pos = tools.scaled_mouse_pos(pg.mouse.get_pos(), scale)
        self.game.update(dt, mouse_pos)
        bets = [x.bet.get_chip_total() for x in self.game.player.hands]
        self.deal_button.visible = any(bets) and not self.game.moving_stacks

        if self.window:
            self.window.update(mouse_pos)
            if self.window.done:
                self.window = None
        else:
            self.lobby_button.update(mouse_pos)
            self.deal_button.update(mouse_pos)
        for stack in self.game.moving_stacks:
            x, y = mouse_pos
            stack.rect.bottomleft = (x - (self.game.chip_size[0] // 2),
                                         y + 6)
Esempio n. 44
0
 def drawUI(self, surface, scale):
     """Update the main surface once per frame"""
     mouse_pos = tools.scaled_mouse_pos(scale, pg.mouse.get_pos())
     self.lobby_button.update(mouse_pos)
     self.new_game_button.update(mouse_pos)
     #
     surface.fill(S['table-color'])
     #
     self.lobby_button.draw(surface)
     self.new_game_button.draw(surface)
     self.all_cards.draw(surface)
     self.ball_machine.draw(surface)
     self.buttons.draw(surface)
     self.card_selector.draw(surface)
     self.money_display.draw(surface)
     self.bonus_display.draw(surface)
     self.bonus_buttons.draw(surface)
Esempio n. 45
0
 def drawUI(self, surface, scale):
     """Update the main surface once per frame"""
     mouse_pos = tools.scaled_mouse_pos(scale, pg.mouse.get_pos())
     self.lobby_button.update(mouse_pos)
     self.new_game_button.update(mouse_pos)
     #
     surface.fill(S['table-color'])
     #
     self.lobby_button.draw(surface)
     self.new_game_button.draw(surface)
     self.all_cards.draw(surface)
     self.ball_machine.draw(surface)
     self.buttons.draw(surface)
     self.card_selector.draw(surface)
     self.money_display.draw(surface)
     self.bonus_display.draw(surface)
     self.bonus_buttons.draw(surface)
Esempio n. 46
0
 def update(self, surface, keys, current, dt, scale, player):
     self.textbox.update()
     if not self.textbox.active:
         self.beep()
         try:
             amount = int(self.textbox.final)
         except ValueError:
             amount = 0
         if amount > player.account.max_advance:
             amount = 0
             self.leave_message("You are not authorized for this amount")
         else:
             player.account.cash_advance(amount)
             player.cash += amount
             msg = "${:.2f} Dispensed".format(amount)
             self.leave_message(msg)
     self.buttons.update(tools.scaled_mouse_pos(scale))
     self.make_dynamic_labels(player)
     self.draw(surface)
Esempio n. 47
0
    def update(self, surface, keys, current, dt, scale, player):
        self.buttons.update(tools.scaled_mouse_pos(scale))
        self.labels = []

        balance = "Account Balance: ${:.2f}".format(player.account.balance)
        self.labels.append(
            Label(self.font, 48, balance, "white", {"topleft": (200, 150)}))
        self.labels.append(
            Label(self.font, 36, "Menu", "white",
                  {"midright": (1278 - 27, 840 + 32)}))
        top = 300
        for transaction, amount in player.account.transactions[::-1]:
            label1 = Label(self.font, 36, transaction, "white",
                           {"topleft": (200, top)})
            label2 = Label(self.font, 36, "${:.2f}".format(amount), "white",
                           {"topright": (1220, top)})
            self.labels.extend([label1, label2])
            top += label1.rect.height
        self.draw(surface)
Esempio n. 48
0
 def update(self, surface, keys, current, dt, scale, player):
     self.textbox.update()
     if not self.textbox.active:
         self.beep()
         try:
             amount = int(self.textbox.final)
         except ValueError:
             amount = 0
         if amount > player.account.max_advance:
             amount = 0
             self.leave_message("You are not authorized for this amount")
         else:
             player.account.cash_advance(amount)
             player.cash += amount
             msg = "${:.2f} Dispensed".format(amount)
             self.leave_message(msg)
     self.buttons.update(tools.scaled_mouse_pos(scale))
     self.make_dynamic_labels(player)
     self.draw(surface)
Esempio n. 49
0
    def update(self, surface, keys, current_time, dt, scale):
        """
        This method will be called once each frame while the state is active.
        Surface is a reference to the rendering surface which will be scaled
        to pygame's display surface, keys is the return value of the last call
        to pygame.key.get_pressed. current_time is the number of milliseconds
        since pygame was initialized. dt is the number of milliseconds since
        the last frame.
        """

        self.advisor.update(dt)

        if self.play_max_active:
            self.continue_playmax()
            self.play_game()

        total_text = "Balance:  ${}".format(self.wallet.balance)

        self.gui_widgets['balance'] = Label(self.font, 48, total_text, "gold3",
                               {"topleft": (24, 760)})

        bet_text = "Bet: ${}".format(self.pot._balance)
        self.gui_widgets['bet'] = Label(self.font, 48, bet_text, "gold3",
                               {"topleft": (24, 760+48)})

        won_text = "Won: ${}".format(self.pot.won)
        self.gui_widgets['won'] = Label(self.font, 48, won_text, "gold3",
                               {"topleft": (24, 760+48+48)})

        spot_count = self.keno_card.spot_count
        spot_text = "Spot: {}".format(spot_count)
        self.gui_widgets['spot'] = Label(self.font, 48, spot_text, "gold3",
                               {"topleft": (1036, 760)})

        mouse_pos = tools.scaled_mouse_pos(scale)
        self.buttons.update(mouse_pos)
        if self.alert:
            self.alert.update(mouse_pos)
            if self.alert.done:
                self.alert = None

        self.draw(surface)
Esempio n. 50
0
    def update(self, surface, keys, current_time, dt, scale):
        """
        This method will be called once each frame while the state is active.
        Surface is a reference to the rendering surface which will be scaled
        to pygame's display surface, keys is the return value of the last call
        to pygame.key.get_pressed. current_time is the number of milliseconds
        since pygame was initialized. dt is the number of milliseconds since
        the last frame.
        """

        self.advisor.update(dt)

        if self.play_max_active:
            self.continue_playmax()
            self.play_game()

        total_text = "Balance:  ${}".format(self.wallet.balance)

        self.gui_widgets['balance'] = Label(self.font, 48, total_text, "gold3",
                                            {"topleft": (24, 760)})

        bet_text = "Bet: ${}".format(self.pot._balance)
        self.gui_widgets['bet'] = Label(self.font, 48, bet_text, "gold3",
                                        {"topleft": (24, 760 + 48)})

        won_text = "Won: ${}".format(self.pot.won)
        self.gui_widgets['won'] = Label(self.font, 48, won_text, "gold3",
                                        {"topleft": (24, 760 + 48 + 48)})

        spot_count = self.keno_card.spot_count
        spot_text = "Spot: {}".format(spot_count)
        self.gui_widgets['spot'] = Label(self.font, 48, spot_text, "gold3",
                                         {"topleft": (1036, 760)})

        mouse_pos = tools.scaled_mouse_pos(scale)
        self.buttons.update(mouse_pos)
        if self.alert:
            self.alert.update(mouse_pos)
            if self.alert.done:
                self.alert = None

        self.draw(surface)
Esempio n. 51
0
    def update(self, surface, keys, current_time, dt, scale):
        """Update all elements and then draw the state."""
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.done_button.update(mouse_pos)
        if self.title:
            if self.title.moving:
                for spinner in self.spinners:
                    spinner.rect.move_ip(self.title.move_speed)
            self.title.update()

        if self.zipper_block and self.title.spun_out:
            self.zipper_block.update(dt)
            if self.zipper_block.done:
                self.switch_blocks()
        if self.chip_curtain:
            self.chip_curtain.update(dt)
            if self.chip_curtain.done:
                self.done = True
        self.spinners.update(dt)
        self.draw(surface)
Esempio n. 52
0
    def update(self, surface, keys, current_time, dt, scale):
        """Update all elements and then draw the state."""
        mouse_pos = tools.scaled_mouse_pos(scale)
        self.done_button.update(mouse_pos)
        if self.title:
            if self.title.moving:
                for spinner in self.spinners:
                    spinner.rect.move_ip(self.title.move_speed)
            self.title.update()

        if self.zipper_block and self.title.spun_out:
            self.zipper_block.update(dt)
            if self.zipper_block.done:
                self.switch_blocks()
        if self.chip_curtain:
            self.chip_curtain.update(dt)
            if self.chip_curtain.done:
                self.done = True
        self.spinners.update(dt)
        self.draw(surface)
Esempio n. 53
0
 def update(self, surface, keys, current, dt, scale, player):
     self.textbox.update()
     if not self.textbox.active:
         self.beep()
         try:
             amount = int(self.textbox.final)
         except ValueError:
             amount = 0
         if player.account.balance >= amount:
             player.account.withdrawal(amount)
             player.cash += amount
             self.leave_message("${:.2f} Withdrawn".format(amount))
         else:
             msg = "Insufficient Funds for Withdrawal"
             self.leave_message(msg)
     self.buttons.update(tools.scaled_mouse_pos(scale))
     text = "You have ${:.2f} available for withdrawal".format(player.account.balance)
     self.dyna_label = Label(
         self.font, 36, text, "white", {"midtop": (self.screen_rect.centerx, self.screen_rect.top + 80)}
     )
     self.draw(surface)
Esempio n. 54
0
    def update(self, surface, keys, current, dt, scale, player):
        self.textbox.update()
        self.buttons.update(tools.scaled_mouse_pos(scale))
        if not self.textbox.active:
            self.beep()
            try:
                amount = int(self.textbox.final)
            except ValueError:
                amount = 0
            if player.cash >= amount:
                player.cash -= amount
                player.account.deposit(amount)
                msg = "${:.2f} Deposited".format(amount)
                self.leave_message(msg)
            else:
                self.leave_message("Insufficient Funds Deposited")
        text = "You have ${:.2f} available for deposit".format(player.cash)
        self.dyna_label = Label(
            self.font, 36, text, "white",
            {"midtop": (self.screen_rect.centerx, self.screen_rect.top + 80)})

        self.draw(surface)
Esempio n. 55
0
 def update(self, surface, keys, current, dt, scale, player):
     self.textbox.update()
     if not self.textbox.active:
         self.beep()
         try:
             amount = int(self.textbox.final)
         except ValueError:
             amount = 0
         if player.account.balance >= amount:
             player.account.withdrawal(amount)
             player.cash += amount
             self.leave_message("${:.2f} Withdrawn".format(amount))
         else:
             msg = "Insufficient Funds for Withdrawal"
             self.leave_message(msg)
     self.buttons.update(tools.scaled_mouse_pos(scale))
     text = "You have ${:.2f} available for withdrawal".format(
         player.account.balance)
     self.dyna_label = Label(
         self.font, 36, text, "white",
         {"midtop": (self.screen_rect.centerx, self.screen_rect.top + 80)})
     self.draw(surface)
Esempio n. 56
0
    def update(self, surface, keys, current, dt, scale, player):
        self.textbox.update()
        self.buttons.update(tools.scaled_mouse_pos(scale))
        if not self.textbox.active:
            self.beep()
            try:
                amount = int(self.textbox.final)
            except ValueError:
                amount = 0
            if player.cash >= amount:
                player.cash -= amount
                player.account.deposit(amount)
                msg = "${:.2f} Deposited".format(amount)
                self.leave_message(msg)
            else:
                self.leave_message("Insufficient Funds Deposited")
        text = "You have ${:.2f} available for deposit".format(player.cash)
        self.dyna_label = Label(
            self.font, 36, text, "white", {"midtop": (self.screen_rect.centerx, self.screen_rect.top + 80)}
        )

        self.draw(surface)
Esempio n. 57
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.buttons.update(mouse_pos)
     self.animations.update(dt)
     self.draw(surface)
Esempio n. 58
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.buttons.update(mouse_pos)
     self.animations.update(dt)
     self.draw(surface)
Esempio n. 59
0
 def update(self, surface, keys, current_time, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.lobby_button.update(mouse_pos)
     self.machine.update(mouse_pos, dt)
     self.draw(surface, dt)
Esempio n. 60
0
 def update(self, dt, scale):
     mouse_pos = tools.scaled_mouse_pos(scale)
     self.general_update(dt, mouse_pos)
     self.make_showdown_label()