示例#1
0
    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
示例#2
0
    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
示例#3
0
 def back_to_lobby(self, *args):
     player = self.game.player
     for hand in player.hands:
         player.chip_pile.add_chips(cash_to_chips(
             hand.bet.get_chip_total()))
     self.leave_state()
示例#4
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)
示例#5
0
 def back_to_lobby(self, *args):
     player = self.game.player
     for hand in player.hands:
         player.chip_pile.add_chips(cash_to_chips(hand.bet.get_chip_total()))
     self.leave_state()
示例#6
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)