Пример #1
0
    def __init__(self):
        self.active = True
        self.group = pg.sprite.Group()
        self.frames = pg.sprite.Group()
        self.advisor = Advisor(self.group, self.frames)
        self.advisor.active = True
        self.images = {
            'back': prepare.GFX["advisor_back"],
            'front': prepare.GFX["advisor_front"],
            'back_dim': prepare.GFX["advisor_back_dim"],
            'front_dim': prepare.GFX["advisor_front_dim"],
        }

        self.rect = self.get_rect()
        self.button = Button(self.rect, call=self.toggle_active)

        # Just testing to ensure it works...
        self.advisor.queue_text("Welcome to Keno!", dismiss_after=2500)
Пример #2
0
    def startup(self, now, persistent):
        self.now = now
        self.persist = persistent
        self.casino_player = self.persist['casino_player']
        self.get_stats_from_casino_player()

        # declared here to appease pycharm's syntax checking.
        # will be filled in when configuration is loaded
        self.betting_areas = dict()
        self.dealer_hand = None
        self.player_hand = None
        self.player_chips = None
        self.house_chips = None
        self.shoe = None

        # baccarat only: move out later
        self.confirm_button_rect = None

        self.interested_events = [
            ('SNAP_STACK', self.on_snap_stack),
            ('RETURN_STACK', self.on_return_stack),
            ('SNAP_STACK_MOTION', self.on_snap_stack_motion),
            ('PICKUP_STACK', self.on_pickup_stack),
            ('DROP_STACK', self.on_drop_stack),
            ('PICKUP_STACK_MOTION', self.on_pickup_stack_motion),
        ]

        names = ["cardshove{}".format(x) for x in (1, 3, 4)]
        self.shove_sounds = [prepare.SFX[name] for name in names]
        names = ["cardplace{}".format(x) for x in (2, 3, 4)]
        self.deal_sounds = [prepare.SFX[name] for name in names]
        names = ["chipsstack{}".format(x) for x in (3, 5, 6)]
        self.chip_sounds = [prepare.SFX[name] for name in names]

        self._allow_exit = True
        self._enable_chips = False
        self._mouse_tooltip = None
        self._background = None
        self._hovered_sprite = None
        self._clicked_sprite = None
        self._hovered_chip_area = None
        self._grabbed_stack = False
        self._locked_advice = None

        self.font = pg.font.Font(prepare.FONTS["Saniretro"], 64)
        self.large_font = pg.font.Font(prepare.FONTS["Saniretro"], 120)
        self.button_font = pg.font.Font(prepare.FONTS["Saniretro"], 48)

        self.hud = SpriteGroup()
        self.bets = MetaGroup()
        self.metagroup = MetaGroup()
        self.metagroup.add(self.bets)
        self.animations = pg.sprite.Group()

        self._advisor = Advisor(self.hud, self.animations)
        self._advisor.queue_text('Welcome to Baccarat', 3000)

        self.hud.add(NeonButton('lobby', (540, 938, 0, 0), self.goto_lobby))

        spr = Sprite()
        spr.image = prepare.GFX['baccarat-menu-front']
        spr.rect = spr.image.get_rect()
        self.hud.add(spr, layer=1)

        spr = Sprite()
        spr.image = prepare.GFX['baccarat-menu-back']
        spr.rect = spr.image.get_rect()
        self.hud.add(spr, layer=-100)

        self.remove_animations = partial(remove_animations_of, self.animations)

        self.metagroup.add(self.hud)

        self.reload_config()
        self.link_events()
        self.cash_in()
        self.new_round()
Пример #3
0
class BlackjackGame(object):
    """Represents a single game of blackjack."""
    draw_group = pg.sprite.Group()
    move_animations = pg.sprite.Group()
    advisor = Advisor(draw_group, move_animations)
    advisor.active = True
    advisor_back = prepare.GFX["advisor_back"]
    advisor_front = prepare.GFX["advisor_front"]
    advisor_back_dim = prepare.GFX["advisor_back_dim"]
    advisor_front_dim = prepare.GFX["advisor_front_dim"]
    font = prepare.FONTS["Saniretro"]
    result_font = prepare.FONTS["Saniretro"]
    deal_sounds = [
        prepare.SFX[name]
        for name in ["cardplace{}".format(x) for x in (2, 3, 4)]
    ]
    chip_sounds = [
        prepare.SFX[name]
        for name in ["chipsstack{}".format(x) for x in (3, 5, 6)]
    ]
    chip_size = (48, 30)
    screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
    advisor_active = True

    def __init__(self, casino_player, player_cash, chips=None, chip_pile=None):
        self.deck = Deck((20, 100), prepare.CARD_SIZE, 40)
        self.dealer = Dealer()
        self.chip_rack = ChipRack((1100, 130), self.chip_size)
        self.moving_stacks = []
        self.casino_player = casino_player
        self.player = Player(self.chip_size, player_cash, chips, chip_pile)
        self.labels = self.make_labels()
        self.current_player_hand = self.player.hands[0]
        self.quick_bet = 0
        self.last_bet = 0
        rect = self.advisor_back.get_rect().union(
            self.advisor_front.get_rect())
        self.advisor_button = Button(rect, call=self.toggle_advisor)

    def make_labels(self):
        labels_info = [("Drop chips in chip rack", 36, "antiquewhite", 100, {
            "midtop":
            (self.chip_rack.rect.centerx, self.chip_rack.rect.bottom + 5)
        }),
                       ("to make change", 36, "antiquewhite", 100, {
                           "midtop": (self.chip_rack.rect.centerx,
                                      self.chip_rack.rect.bottom + 60)
                       }),
                       ("Blackjack Pays 3 to 2", 64, "gold3", 120, {
                           "midtop": (580, 300)
                       }),
                       ("Dealer must draw to 16 and stand on 17", 48,
                        "antiquewhite", 100, {
                            "midtop": (580, 240)
                        })]
        labels = []
        for info in labels_info:
            label = Label(self.font,
                          info[1],
                          info[0],
                          info[2],
                          info[4],
                          bg=prepare.FELT_GREEN)
            label.image.set_alpha(info[3])
            labels.append(label)
        return labels

    def toggle_advisor(self, *args):
        BlackjackGame.advisor_active = not BlackjackGame.advisor_active

    def tally_hands(self):
        """
        Calculate result of each player hand and set appropriate
        flag for each hand.
        """
        if self.dealer.hand.blackjack:
            for hand in self.player.hands:
                hand.loser = True
        elif self.dealer.hand.busted:
            for hand in self.player.hands:
                if not hand.busted and not hand.blackjack:
                    hand.winner = True
        else:
            d_score = self.dealer.hand.best_score()
            for hand in self.player.hands:
                if not hand.busted:
                    p_score = hand.best_score()
                    if p_score == 21 and len(hand.cards) == 2:
                        hand.blackjack = True
                    elif p_score < d_score:
                        hand.loser = True
                    elif p_score == d_score:
                        hand.push = True
                    else:
                        hand.winner = True

    def pay_out(self):
        """
        Calculate player win amounts, update stats and return chips
        totalling total win amount.
        """
        cash = 0
        for hand in self.player.hands:
            bet = hand.bet.get_chip_total()
            self.casino_player.increase("hands played")
            self.casino_player.increase("total bets", bet)
            if hand.busted:
                self.casino_player.increase("busts")
                self.casino_player.increase("hands lost")
            elif hand.loser:
                self.casino_player.increase("hands lost")
            elif hand.blackjack:
                cash += int(bet * 2.5)
                self.casino_player.increase("blackjacks")
                self.casino_player.increase("hands won")
            elif hand.winner:
                cash += bet * 2
                self.casino_player.increase("hands won")
            elif hand.push:
                cash += bet
                self.casino_player.increase("pushes")

        self.casino_player.increase("total winnings", cash)
        chips = cash_to_chips(cash, self.chip_size)
        return chips

    def get_event(self, event):
        self.advisor_button.get_event(event)

    def update(self, dt, mouse_pos):
        self.advisor_button.update(mouse_pos)
        total_text = "Chip Total:  ${}".format(
            self.player.chip_pile.get_chip_total())
        screen = self.screen_rect
        self.chip_total_label = Label(
            self.font, 48, total_text, "gold3",
            {"bottomleft": (screen.left + 3, screen.bottom - 3)})
        self.chip_rack.update()
        if self.advisor_active:
            self.move_animations.update(dt)
Пример #4
0
class GutsState(object):
    font = prepare.FONTS["Saniretro"]
    deal_sounds = [prepare.SFX["cardshove{}".format(x)] for x in (1, 3, 4)]
    flip_sounds = [prepare.SFX["cardplace{}".format(x)] for x in (2, 3, 4)]
    cha_ching = prepare.SFX["coins"]
    screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
    money_icon = MoneyIcon((0, screen_rect.bottom - 75))
    draw_group = pg.sprite.Group()
    move_animations = pg.sprite.Group()
    advisor = Advisor(draw_group, move_animations)
    advisor.active = True
    advisor_back = prepare.GFX["advisor_back"]
    advisor_front = prepare.GFX["advisor_front"]
    advisor_back_dim = prepare.GFX["advisor_back_dim"]
    advisor_front_dim = prepare.GFX["advisor_front_dim"]
    advisor_active = True
    window = None

    def __init__(self):
        self.done = False
        self.quit = False
        self.next = None
        rect = self.advisor_back.get_rect().union(
            self.advisor_front.get_rect())
        self.advisor_button = Button(rect, call=self.toggle_advisor)
        self.buttons = ButtonGroup()
        pos = (self.screen_rect.right - (NeonButton.width + 10),
               self.screen_rect.bottom - (NeonButton.height + 10))
        lobby_button = NeonButton(pos,
                                  "Lobby",
                                  self.back_to_lobby,
                                  None,
                                  self.buttons,
                                  bindings=[pg.K_ESCAPE])
        self.animations = pg.sprite.Group()

    def warn(self, *args):
        warning = "Exiting the game will abandon the current pot!"
        GutsState.window = WarningWindow(self.screen_rect.center, warning,
                                         self.leave)

    def notice(self, msg):
        GutsState.window = NoticeWindow(self.screen_rect.center, msg)

    def back_to_lobby(self, *args):
        if self.game.pot:
            self.warn()
        else:
            self.leave()

    def leave(self):
        self.quit = True
        self.advisor.empty()

    def toggle_advisor(self, *args):
        GutsState.advisor_active = not GutsState.advisor_active

    def draw_advisor(self, surface):
        if self.advisor_active:
            surface.blit(self.advisor_back, (0, 0))
            self.draw_group.draw(surface)
            surface.blit(self.advisor_front, (0, 0))
        else:
            surface.blit(self.advisor_back_dim, (0, 0))
            surface.blit(self.advisor_front_dim, (0, 0))

    def general_update(self, dt, mouse_pos):
        if self.window:
            self.window.update(mouse_pos)
            if self.window.done:
                GutsState.window = None
        else:
            self.advisor_button.update(mouse_pos)
            self.animations.update(dt)
            self.buttons.update(mouse_pos)
            self.money_icon.update(self.game.player.cash)
            self.advisor_button.update(mouse_pos)
            if self.advisor_active:
                self.move_animations.update(dt)
            self.game.update()

    def startup(self, game):
        self.game = game

    def update(self, dt, scale):
        pass

    def get_event(self, event):
        pass

    def draw(self, surface):
        pass

    def play_deal_sound(self):
        choice(self.deal_sounds).play()

    def play_flip_sound(self):
        choice(self.flip_sounds).play()

    def play_stay_sound(self):
        choice(self.stay_sounds).play()

    def play_pass_sound(self):
        choice(self.fold_sounds).play()