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")
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)
def stay_out(self, *args): self.current_player.stay_out() self.game.casino_player.increase("passes") self.animations.add(Task(self.end_player_turn, 1000)) self.toggle_player_buttons(False)