Exemple #1
0
    def __init__(self, topleft, size):
        self.rect = pg.Rect(topleft, size)

        self.deck = Deck((20, 20), card_size=(187, 271), infinite=True)

        self.hand = []
        self.hand_len = 0
        self.card_index = None
        self.max_cards = None
        self.revealing = False
        self.held_cards = []
        self.changing_cards = []
        self.waiting = False
        self.playing = False
        self.double_up = False

        self.font = prepare.FONTS["Saniretro"]
        self.text_size = 30
        self.big_text_size = 100
        self.line_height = 35
        self.text_color = "white"
        self.big_text_color = "red"
        self.text_bg_color = "darkblue"

        self.held_labels = []
        self.double_up_labels = []

        self.text = " insert coins "
        self.no_playing_label = Blinker(self.font, self.big_text_size, self.text, self.big_text_color,
                                        {"center": self.rect.center}, 700, self.text_bg_color)

        self.text = " play 1 to 5 coins "
        self.waiting_label = Blinker(self.font, self.big_text_size, self.text, self.big_text_color,
                                     {"center": self.rect.center}, 700, self.text_bg_color)

        self.card_spacing = 30

        self.animation_speed = 170.0
        self.elapsed = self.animation_speed

        self.deal_sound = prepare.SFX["cardplace2"]
        self.held_sound = prepare.SFX["bingo-ball-chosen"]
    def make_help_labels(self, rect):
        labels = []
        text = "Double up ?"
        label = Blinker(self.font, 100, text, "red", {
            "centerx": rect.centerx,
            "top": rect.top
        }, 700)
        labels.append(label)
        text = "If selected card beats dealers, player wins. Ace is highest, two is lowest"
        label = MultiLineLabel(self.font,
                               self.text_size,
                               text,
                               self.text_color, {"center": rect.center},
                               align="center")
        labels.append(label)

        return labels
Exemple #3
0
    def startup(self, game):
        self.game = game
        self.game.result_labels = []
        self.fade_labels = []
        self.alpha = 255
        total_ani_time = 2000
        fade_ani = Animation(alpha=0, duration=total_ani_time)
        fade_ani.start(self)
        self.animations.add(fade_ani)
        self.game.tally_hands()
        payout = self.game.pay_out()
        if payout:
            self.coin_sound.play()
        hands = self.game.player.hands
        if len(hands) > 2:
            text_size = 64
        elif len(hands) == 2:
            text_size = 80
        else:
            text_size = 96
        win_piles = []
        loss_piles = []
        self.winnings = []
        self.losses = []
        for hand in hands:
            amount = hand.bet.get_chip_total()
            hand.bet_amount = amount
            bl = hand.bet.stacks[0].rect.bottomleft
            if hand.blackjack:
                text, color = "Blackjack", "gold3"
                text_size -= 8
                chips = cash_to_chips(int(amount * 2.5))
                amount = int(amount * 1.5)
                win_piles.append(BetPile(bl, self.game.chip_size, chips))
            elif hand.winner:
                text, color = "Win", "gold3"
                chips = cash_to_chips(amount * 2)
                win_piles.append(BetPile(bl, self.game.chip_size, chips))
            elif hand.push:
                text, color = "Push", "gold3"
                chips = cash_to_chips(amount)
                win_piles.append(BetPile(bl, self.game.chip_size, chips))
            elif hand.busted:
                text, color = "Bust", "darkred"
                chips = cash_to_chips(amount)
                loss_piles.append(BetPile(bl, self.game.chip_size, chips))
                amount *= -1
            else:
                text, color = "Loss", "darkred"
                chips = cash_to_chips(amount)
                loss_piles.append(BetPile(bl, self.game.chip_size, chips))
                amount *= -1
            centerx = (hand.slots[0].left + hand.slots[-1].right) // 2
            centery = hand.slots[0].centery
            label = Blinker(self.font, text_size, text, color,
                            {"center": (centerx, centery)}, 450)
            self.game.result_labels.append(label)
            amt_color = "darkgreen" if amount >= 0 else "darkred"

            bet_label = Label(self.font,
                              120,
                              "{:+}".format(amount),
                              amt_color, {"bottomleft": bl},
                              bg=prepare.FELT_GREEN)
            move_ani = Animation(bottom=bl[1] - 150,
                                 duration=total_ani_time,
                                 round_values=True)
            move_ani.start(bet_label.rect)
            self.animations.add(move_ani)
            self.fade_labels.append(bet_label)
            hand.bet.chips = []
            hand.bet.stacks = []

        payout_duration = 1000
        center = self.game.player.chip_pile.rect.center
        for pile in win_piles:
            self.winnings.append(pile)
            for stack in pile.stacks:
                ani = Animation(left=center[0],
                                bottom=center[1],
                                duration=payout_duration,
                                round_values=True)
                ani.start(stack.rect)
                self.animations.add(ani)
        center = self.game.chip_rack.rect.center
        for loss_pile in loss_piles:
            self.losses.append(loss_pile)
            for stack in loss_pile.stacks:
                ani = Animation(left=center[0],
                                bottom=center[1],
                                duration=payout_duration,
                                round_values=True)
                ani.start(stack.rect)
                self.animations.add(ani)
        pay_ani = Task(self.game.player.chip_pile.add_chips,
                       payout_duration,
                       args=[payout])
        remove_chips = Task(self.remove_chips, payout_duration)
        end_it = Task(self.end_state, total_ani_time)
        self.animations.add(pay_ani, remove_chips, end_it)
Exemple #4
0
    def startup(self, game):
        self.game = game
        self.lobby_button.call = self.warn
        self.toggled = False
        self.alpha = 255
        self.labels = []
        self.blinkers = []
        self.calculated = False
        self.animations = pg.sprite.Group()

        stayers = [x for x in self.game.players if x.stayed]
        winners = self.game.get_winners()
        share = self.game.pot // len(winners)

        ani_duration = 2000
        self.free_ride = False

        for stayer in stayers:
            pos = stayer.name_label.rect.center
            dest = pos[0], pos[1] - 120
            cards_center = stayer.cards[0].rect.union(
                stayer.cards[1].rect).center
            if stayer not in winners:
                text = "${}".format(self.game.pot)
                color = "darkred"
                stayer.lost = self.game.pot
                self.free_ride = True
                dest = self.game.pot_label.rect.center
                if stayer is self.game.player:
                    pos = self.money_icon.rect.center
                    if self.game.player.cash < stayer.lost:
                        amount = stayer.lost - self.game.player.cash
                        self.cash_advance(amount)
                        msg = "You were forced to take a cash advance to cover your loss. Visit the ATM to view your account."
                        self.notice(msg)
                    self.add_player_cash(-stayer.lost)
                task = Task(self.add_to_pot, ani_duration, args=[stayer.lost])
                self.animations.add(task)
                lose_label = Blinker(self.font, 96, "Loser", color,
                                     {"center": cards_center}, 500)
                self.animations.add(
                    Task(self.blinkers.append, ani_duration,
                         args=[lose_label]))
            else:
                text = "${}".format(share)
                color = "darkgreen"
                stayer.won = share
                pos = self.game.pot_label.rect.center
                if stayer is self.game.player:
                    self.cha_ching.play()
                    dest = self.money_icon.rect.center
                    task = Task(self.add_player_cash,
                                ani_duration,
                                args=[share])
                    self.animations.add(task)
                win_label = Blinker(self.font, 96, "Winner", color,
                                    {"center": cards_center}, 500)
                self.animations.add(
                    Task(self.blinkers.append, ani_duration, args=[win_label]))
            label = Label(self.font,
                          128,
                          text,
                          color, {"center": pos},
                          bg=prepare.FELT_GREEN)
            label.image.set_colorkey(prepare.FELT_GREEN)
            self.labels.append(label)
            move = Animation(centerx=dest[0],
                             centery=dest[1],
                             duration=ani_duration,
                             round_values=True,
                             transition="in_quart")
            move.start(label.rect)
            self.animations.add(move)

        fader = Animation(alpha=0,
                          duration=ani_duration + 200,
                          round_values=True)
        fader.start(self)
        self.animations.add(fader)
        self.game.pot = 0

        self.make_player_buttons(self.free_ride)
        self.toggle_buttons(False)
        if self.free_ride:
            self.advice_texts = ["Press OK to play the next round"]
        else:
            self.advice_texts = [
                "Ante Up ${} to play again".format(self.game.bet)
            ]
        self.advice_texts.append("Press the Lobby button to exit")