def payout(self): """Pays winnings to each player.""" # Maybe create functions like bustedPayout() and blackjackPayout()? # For readability. dealer_hand = self.dealer.hand_list[self.dealer.current_hand] for player in self.players: for hand in player.hand_list: if (hand.blackjack_hand): # Draw doesn't get checked here, has to be moved. player.balance += hand.bet player.balance += hand.bet * self.rules.win_blackjack_factor player.stats.bjs += 1 elif (r.busted(hand, self.rules)): player.stats.busts += 1 if (r.busted(dealer_hand, self.rules) and self.rules.money_back_on_draw): player.balance += hand.bet else: # Give the bet to the dealer. self.dealer.balance += hand.bet elif (r.value(hand) > r.value(dealer_hand) or r.busted(dealer_hand, self.rules)): player.stats.wins += 1 player.balance += hand.bet player.balance += hand.bet * self.rules.win_payout_factor self.dealer.balance -= hand.bet elif (r.value(hand) == r.value(dealer_hand) and self.rules.money_back_on_draw): player.stats.draws += 1 player.balance += hand.bet else: #hand lost. no payout needed, because bets are already taken when betting. self.dealer.balance += hand.bet player.stats.losses += 1
def payout(self): """Pays winnings to each player.""" # Maybe create functions like bustedPayout() and blackjackPayout()? # For readability. dealer_hand = self.dealer.hand_list[self.dealer.current_hand] for player in self.players: for hand in player.hand_list: if (hand.blackjack_hand): # Draw doesn't get checked here, has to be moved. player.balance += hand.bet player.balance += hand.bet * self.rules.win_blackjack_factor player.stats.bjs += 1 elif (r.busted(hand, self.rules)): player.stats.busts += 1 if (r.busted(dealer_hand, self.rules) and self.rules.money_back_on_draw): player.balance += hand.bet else: # Give the bet to the dealer. self.dealer.balance += hand.bet elif (r.value(hand) > r.value(dealer_hand) or r.busted(dealer_hand, self.rules)): player.stats.wins += 1 player.balance += hand.bet player.balance += hand.bet*self.rules.win_payout_factor self.dealer.balance -= hand.bet elif (r.value(hand) == r.value(dealer_hand) and self.rules.money_back_on_draw): player.stats.draws += 1 player.balance += hand.bet else: #hand lost. no payout needed, because bets are already taken when betting. self.dealer.balance += hand.bet player.stats.losses += 1
def play_round(self): self.betting() self.deal() # remindererer for player in self.players: player.current_hand = 0 for hand in player.hand_list: while (not (r.busted(hand, self.rules) or hand.final_hand)): if self.GUI: # GUI Action loop. # Show what we have. gui.show_game(self) action = 0 gui.actionhelper = 0 # Get action... not really event-driven. while action == 0: # Enter a new level of purkkakoodi action = gui.ctl.get_action() time.sleep(0.5) else: # CLUI action loop ui.print_status(self) action = ui.round_menu(player, hand) if (action == 'h'): player.hit(self.pack) elif (action == 'd'): player.double(self.pack) elif (action == 's'): player.stand(hand) else: # ui.py should take care of never ending here. print msg.unknown_action player.current_hand += 1 # Dealer plays while (r.value(self.dealer.hand_list[0]) < self.rules.dealer_hand_min_value): self.dealer.hit(self.pack) if not self.GUI: ui.print_status(self) else: pass #do GUI relevant stuff. self.payout() self.discard_cards_in_play() # Here until nicer UI. if not self.GUI: ui.print_status(self) else: pass #do GUI relevant stuff. self.save_players() self.round_cleanup()