def initiate_game(): dealer = blackjack.Player() player1 = blackjack.Player() player1.bank_roll = 500 deck = blackjack.Deck() deck.shuffle(5) player1.show_bank_roll() player1.wager() for i in range(2): player1.hand.append(deck.cards.pop()) dealer.hand.append(deck.cards.pop()) player1.reorder() dealer.reorder() print("You were dealt...") player1.show_hand() player1.total() print("\nThe dealer is showing...") dealer.show_card() player1.hit_or_stay(deck)
def test_unique_deck(self): deck = blackjack.Deck(jokers=0) print(deck) player = blackjack.Player(100, deck) print(player.hand) print(deck) self.assertEqual(len(deck.cards), 50)
def setUp(self): self.player = blackjack.Player()
def test_player_unique_start_balance(self): name = "Joe" balance = "50" new_player = blackjack.Player(name, balance) result = str(new_player) self.assertEqual(result, "Joe, you have $50 left.")
import blackjack deck = blackjack.Deck() dealer = blackjack.Player(blackjack.deal_card(deck), blackjack.deal_card(deck)) # Processes a human player; dealer remains hidden while True: # Holds all player instances to be used as arguments for functions player_pool = [] # Gets how many players are playing number_of_players = input("How many people are playing? ") if int(number_of_players) == 0: print("Goodbye") break # Creates specified number of players and appends them to list for number in range(int(number_of_players)): player_pool.append( blackjack.Player(blackjack.deal_card(deck), blackjack.deal_card(deck))) # For loop goes through the list of players and plays game for each for i in range(len(player_pool)): print("\nNow playing player " + str(i + 1)) blackjack.play_hand(player_pool[i], deck) # Add in the dealer and play its turn player_pool.append(dealer)
import blackjack from time import sleep DEALER = blackjack.Dealer() PLAYER = blackjack.Player() def main_menu(): prompt = "\n1. play\n2. quit game\n\nSelect an option (1-2): " user_input = get_valid_input(prompt, ['1', '2']) if user_input == '1': game() main_menu() elif user_input == '2': exit() else: print("\n\tInvalid Input!\n") main_menu() def game(): #INITIALIZE VARIABLES global DEALER global PLAYER DEALER.new_deck() print( "\n-------------------------\n Dealer shuffles deck \n-------------------------\n" )
def test_place_invalid_bet(self): deck = blackjack.Deck(jokers=0) player = blackjack.Player(100, deck) self.assertRaises(ValueError, player.place_bet, 120)
def test_place_valid_bet(self): deck = blackjack.Deck(jokers=0) player = blackjack.Player(100, deck) player.place_bet(12) self.assertEqual(88, player.balance)
def test_player_cration(self): deck = blackjack.Deck(jokers=0) player = blackjack.Player(100, deck) self.assertEqual(len(player.hand.cards), 2)