def update_status(self, game): dealer_hand = game.dealer.hand_list[0] self.set_dealer_status(str(dealer_hand) + ' (' + str(r.value(dealer_hand)) + ')') plr = game.players[0] # GUI is single plr plr_hand = plr.hand_list[plr.current_hand] self.set_player_status(str(plr_hand) + ' (' + str(r.value(plr_hand)) + ')')
def update_cards(self, game): dealer_hand = game.dealer.hand_list[0] self.set_dealer_hand_label(str(r.value(dealer_hand))) plr = game.players[0] # GUI is single plr plr_hand = plr.hand_list[plr.current_hand] self.set_player_hand_label(str(r.value(plr_hand))) self.repaint() for card in dealer_hand.card_stack: self.dealer_hand_layout.addWidget(CardLabel(card)) for card in plr_hand.card_stack: self.player_hand_layout.addWidget(CardLabel(card)) self.show()
def print_status(game): print "Status:" print "Dealer's hand:\t", game.dealer.hand_list[game.dealer.current_hand] print "Dealer's hand value:", r.value(game.dealer.hand_list[game.dealer.current_hand]) print for plr in game.players: i = 0 print plr, "balance:", plr.balance, print plr, "has", len(plr.hand_list), "hands:" for hand in plr.hand_list: i += 1 print "Player", plr, "hand #" + str(i), "is", hand print "With a value of", r.value(hand) print print print
def print_status(game): print "Status:" print "Dealer's hand:\t", game.dealer.hand_list[game.dealer.current_hand] print "Dealer's hand value:", r.value( game.dealer.hand_list[game.dealer.current_hand]) print for plr in game.players: i = 0 print plr, "balance:", plr.balance, print plr, "has", len(plr.hand_list), "hands:" for hand in plr.hand_list: i += 1 print "Player", plr, "hand #" + str(i), "is", hand print "With a value of", r.value(hand) print print print
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 round_menu(player, hand): print "Player", str(player) + "'s turn, hand #" + str( player.current_hand + 1) + ": value:", r.value( player.hand_list[player.current_hand]) print hand action = str(raw_input(Texts.action_prompt + Texts.round_actions)) if action not in Actions.valid_round_actions: return round_menu(player, hand) else: return action
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()
def round_menu(player, hand): print "Player", str(player) + "'s turn, hand #" + str(player.current_hand + 1) +": value:", r.value(player.hand_list[player.current_hand]) print hand action = str(raw_input(Texts.action_prompt + Texts.round_actions)) if action not in Actions.valid_round_actions: return round_menu(player, hand) else: return action