Пример #1
0
    def game(self):
        player_turn = True
        print('Welcome to BlackJack!')
        name = input("What's your name? ")
        curr_chips = 100
        while True:
            player = Player(name)
            dealer = Player("Dealer")

            # setup the game
            deck = Deck()
            deck.shuffle()
            player_hand = Hand()
            player_hand.add_card(deck.deal())
            player_hand.add_card(deck.deal())

            dealer_hand = Hand()
            dealer_hand.add_card(deck.deal())
            dealer_hand.add_card(deck.deal())

            player_chips = Chips(curr_chips)
            print(f'You have {player_chips.total} chips.')
            player_chips.take_bet(player_chips)

            self.show_cards(player_hand, dealer_hand)

            while player_turn:
                if player.hit_or_stand(deck, player_hand) == "h":
                    self.show_cards(player_hand, dealer_hand)
                else:
                    break
                if player_hand.value > 21:
                    self.show_all_cards(player_hand, dealer_hand)
                    player.player_busts(player_hand, dealer_hand, player_chips)
                    break

            if player_hand.value <= 21:

                while dealer_hand.value < 17:
                    dealer.hit(deck, dealer_hand)
                    self.show_all_cards(player_hand, dealer_hand)

                if dealer_hand.value > 21:  # dealer lose
                    dealer.dealer_busts(player_hand, dealer_hand, player_chips)
                elif dealer_hand.value > player_hand.value:  # dealer win
                    dealer.dealer_wins(player_hand, dealer_hand, player_chips)
                elif dealer_hand.value < player_hand.value:  # player win
                    player.player_wins(player_hand, dealer_hand, player_chips)
                else:  # tied
                    player.tie(player_hand, dealer_hand)

            print(f'{player.name} has {player_chips.total} chips.')
            curr_chips = player_chips.total
            play_again = input("Play Again? y or n: ")

            if play_again[0].lower() == 'y':
                player_turn = True
            else:
                break
            continue
Пример #2
0
    def __init__(self):
        # Create & shuffle the deck
        self.deck = Deck()
        self.deck.shuffle()

        self.chips = Chips()

        self.game_round = 1

        # Finally, declare a Boolean value to be used to control while loops.
        self.playing = True
Пример #3
0
def test_chips_balance_false():
    chips = Chips()
    assert not chips.check_balance()
    # There are no chips
    chips.total = 100
    chips.bet = 100
    chips.lose_bet()
    assert not chips.check_balance()
Пример #4
0
def play_game():
    global playing, player_hand, dealer_hand, deck
    while True:
        print('Welcome to BlackJack! Get as close to 21 as you can without going over!\n\
        Dealer hits until she reaches 17. Aces count as 1 or 11.')

        create_and_shuffle_deck()
        create_player_hand()
        create_dealer_hand()

        player_chips = Chips()
        take_bet(player_chips)
        show_some(player_hand, dealer_hand)

        while playing:

            # Prompt for Player to Hit or Stand
            hit_or_stand(deck, player_hand)
            show_some(player_hand, dealer_hand)

            if player_hand.value > 21:
                player_busts(player_chips)
                break

        # If Player hasn't busted, play Dealer's hand
        if player_hand.value <= 21:

            while dealer_hand.value < 17:
                hit(deck, dealer_hand)

            # Show all cards
            show_all(player_hand, dealer_hand)

            # Test different winning scenarios
            if dealer_hand.value > 21:
                dealer_busts(player_chips)

            elif dealer_hand.value > player_hand.value:
                dealer_wins(player_chips)

            elif dealer_hand.value < player_hand.value:
                player_wins(player_chips)

            else:
                push()

            # Inform Player of their chips total
            print("\nPlayer's winnings stand at total of ", player_chips.total)

        # Ask to play again
        new_game = input("Would you like to play another hand? Enter 'y' or 'n' ")
        if new_game[0].lower() == 'y':
            playing = True
            continue
        else:
            print("Thanks for playing!")
            break

        break
Пример #5
0
def play():

    while True:
        playing = True
        print('Welcome to Blackjack')

        deck = Deck()
        deck.shuffle()

        player_hand = Hand()
        player_hand.add_card(deck.deal())
        player_hand.add_card(deck.deal())

        dealer_hand = Hand()
        dealer_hand.add_card(deck.deal())
        dealer_hand.add_card(deck.deal())

        player_chips = Chips()

        take_bet(player_chips)

        show_some(player_hand, dealer_hand)

        while playing:

            playing = hit_or_stand(deck, player_hand, playing)
            show_some(player_hand, dealer_hand)

            if player_hand.value > 21:
                player_busts(player_hand, dealer_hand, player_chips)
                break

            if player_hand.value <= 21:

                while dealer_hand.value < 17:
                    hit(deck, dealer_hand)

                show_all(player_hand, dealer_hand)

                if dealer_hand.value > 21:
                    dealer_busts(player_hand, dealer_hand, player_chips)
                elif dealer_hand.value > player_hand.value:
                    dealer_wins(player_hand, dealer_hand, player_chips)
                elif dealer_hand.value < player_hand.value:
                    player_wins(player_hand, dealer_hand, player_chips)
                else:
                    push(player_hand, dealer_hand)

            print('\n Player total chips are at {}'.format(player_chips.total))

        new_game = input("Would you like to play another hand? y/n")

        if new_game[0].lower() == 'y':
            playing = True
            continue
        else:
            print('Thank you for playing!')
            break
Пример #6
0
class Game:
    """The game contains the Player's chips and the deck. """
    def __init__(self):
        # Create & shuffle the deck
        self.deck = Deck()
        self.deck.shuffle()

        self.chips = Chips()

        self.game_round = 1

        # Finally, declare a Boolean value to be used to control while loops.
        self.playing = True

    def play_game(self):
        # A game has started
        self.chips.ask_chips()

        while True:
            # Initiate a new round and play the round
            new_round = Round(self)
            new_round.play_round()

            # Ask to play again
            self.playing = input(
                "Do you want to play again? Yes (press any key) or No (press Enter)? "
            )

            balance = self.chips.check_balance()

            if self.playing and balance:
                # Wants to play again and has a balance
                self.game_round += 1
                continue

            else:
                # Wants to exit
                print("Thanks for playing!")
                break
Пример #7
0
    def takeChipOrder(self):
        wantChips = input("Want some chips? Enter Y for yes or N for no")
        if wantChips == 'Y' or wantChips == 'y':
            chipQty = input("How many bags of chips would you like? ")
            chips = Chips(chipQty)
            chipsList = ["chips", "qty:" + str(chips.quantity),
                          chips.price]
            return chipsList
            
        elif wantChips != 'Y' and wantChips != 'y' and \
                wantChips != 'N' and wantChips != 'n':
            print("Invalid input, enter 'Y' for yes or 'N' for no")
            wantChips = input("Want some chips? Enter Y for yes or N for no")
            if wantChips == 'Y' or wantChips == 'y':
                chipQty = input("How many bags of chips would you like? ")
                chips = Chips(chipQty)
                chipsList = ["chips", "qty:" + str(chips.quantity),
                             chips.price]
                return chipsList

        elif wantChips == 'N' or wantChips == 'n':
            chipsList = ["chips", "qty: 0", 0.0]
            return chipsList
Пример #8
0
# Dealer hits until it reaches 17
# Aces count as 1 or 11
# At the start of game the player hwill ave 100 Chips
###############################################################################

import random
from Card import Card
from Deck import Deck
from Hand import Hand
from Error import Error
from Chips import Chips

## Game Logic
if __name__ == "__main__":

    total_chips = Chips()
    print("Welcome to the BlackJack Game")

    while True:
        print("How many chips would you like to bet? (1-100):")

        # Check if the chips count enetered is an integer valules and enough count to play
        chip_count = Error().chip_error(total_chips.total)
        player = Hand()
        dealer = Hand()
        card_in_game = Deck(Card().all_card)

        # Use random function to generate cards for the player and dealers
        # First card for the dealer
        random_choice = random.choices(card_in_game.cards)
        # Pop by index for the card in game
Пример #9
0
	def __init__(self, chips = 0):
		self.chips = Chips(chips)
		self.hand = Hand()
Пример #10
0
    At first player have 100 Chips , Game Over if player have 0 Chips Or When player Decides to leave

'''

import random
from Card import Card
from Deck import Deck
from Hand import Hand
from Hand import Beautiful_printing
from Error import Error
from Chips import Chips

# GAMEPLAY!
if __name__ == "__main__":

    player_Chips = Chips()
    print("Welcome to BlackJack!")

    while (True):
        print("How many chips would you like to bet? you have now {} ".format(
            player_Chips.total))

        # if y is int  , and you have Enough Chips to Play
        y = Error().Error_bet(player_Chips.total)
        player = Hand()
        dealer = Hand()
        card_in_game = Deck(Card().all_card)

        #  1 card to dealer
        random_choice = random.choices(
            card_in_game.cards)  # random ...[('3', 'Hearts')]....
Пример #11
0
    )

    # Create & shuffle the deck, deal two cards to each player
    deck = Deck()
    deck.shuffle()

    player_hand = Hand()
    player_hand.add_card(deck.deal())
    player_hand.add_card(deck.deal())

    dealer_hand = Hand()
    dealer_hand.add_card(deck.deal())
    dealer_hand.add_card(deck.deal())

    # Set up the Player's chips
    player_chips = Chips()  # remember the default value is 100

    # Prompt the Player for their bet
    take_bet(player_chips)

    # Show cards (but keep one dealer card hidden)
    show_some(player_hand, dealer_hand)

    while playing:  # recall this variable from our hit_or_stand function

        # Prompt for Player to Hit or Stand
        hit_or_stand(deck, player_hand)

        # Show cards  (but keep one dealer card hidden)
        show_some(player_hand, dealer_hand)
Пример #12
0
    print("PLAYERS CARDS:")
    for card in player.cards:
        playerSum += card.value
        player.value = playerSum
        print(card)
    print(f"Current Player Hand Value: {player.value}")
    print("DEALERS CARDS:")
    for card in dealer.cards:
        dealerSum += card.value
        dealer.value = dealerSum
        print(card)
    print(f"Current Dealer Hand Value: {dealer.value}")


playing = True
chips = Chips(200)

while True:
    win = False
    playerBusted = False
    print("Welcome to Python BlackJack")

    cardDeck = Deck()
    player = Hand()
    dealer = Hand()
    cardDeck.shuffle()
    initGame(cardDeck, player, dealer)
    chips.bet = placeBet(chips)
    showSome(player, dealer)

    while playing:
Пример #13
0
    print(f'Player has total value {player.show()}')
    print(f'Dealer card value is {dealer.show()}')
    return player.show(), dealer.show()


def show_all(player, dealer):
    print(f'Player has {player.adjust_for_ace()}')
    print(f'Dealer has {dealer.adjust_for_ace()}')
    return player.adjust_for_ace(), dealer.adjust_for_ace()


if __name__ == '__main__':
    chip = ''
    while not chip.isdigit():
        chip = input('How many chips do you have? ')
    chips = Chips(int(chip))
    player = Player()
    dealer = Dealer()
    player.chips = 200
    while True:
        print(f'Your total Chips is {chips.total}')
        deck = Deck()
        deck.shuffle()
        player.cards = []
        dealer.cards = []
        player.value = 0
        dealer.value = 0
        bet = 0
        bet += take_bet(chips.total - bet)
        player.add_card(deck.deal())
        dealer.add_card(deck.deal())
Пример #14
0
    def __init__(self):

        self.chips = Chips()
        self.hand = Hand()
Пример #15
0
def dealer_busts(player, dealer, chips):
    print("\nDealer busts!")
    chips.win_bet()


def dealer_wins(player, dealer, chips):
    print("\nDealer wins!")
    chips.lose_bet()


def push(player, dealer):
    print("\nDealer and Player tie! It's a push.")


chips = Chips()
end_game = False
sec_deck = []
deck = Deck()
deck.shuffle()

print(
    'Welcome to BlackJack! Get as close to 21 as you can without going over!\n\
    Dealer hits until she reaches 17. Aces count as 1 or 11.\n')

while True:

    playing = True

    if len(deck.deck) < 10:
        for card in sec_deck:
Пример #16
0
while True:
    print('Welcome to black jack !')

    deck = Deck()
    deck.shuffle()

    player_hand = Hand()
    player_hand.add_card(deck.deal())
    player_hand.add_card(deck.deal())

    dealer_hand = Hand()
    dealer_hand.add_card(deck.deal())
    dealer_hand.add_card(deck.deal())

    player_chips = Chips()

    take_bet(player_chips)

    show_some(player_hand, dealer_hand)

    while globals.playing:
        hit_or_stand(deck, player_hand)
        show_some(player_hand, dealer_hand)

        if player_hand.value > 21:
            player_busts(player_chips)
            break

    if player_hand.value <= 21:
        while dealer_hand.value < player_hand.value:
Пример #17
0
 def test_loss(self):
     chips = Chips()
     chips.total = 1000
     chips.bet = 10
     chips.loss()
     self.assertEqual(chips.total, 990)
Пример #18
0
 def test_bj_win(self):
     chips = Chips()
     chips.total = 1000
     chips.bet = 10
     chips.bj_win()
     self.assertEqual(chips.total, 1015)
Пример #19
0
def test_chips_balance_true():
    chips = Chips()
    chips.total = 100
    # There are chips, return true
    assert chips.check_balance()
Пример #20
0
 def __init__(self, name):
     super().__init__(name)
     self.chips = Chips()
Пример #21
0
def run_game():

  player_chips = Chips()

  while True:
    #Print an opening statement
    print("Welcome to BlackJack!\nGet as close to 21 as you can without going over!\nDealer hits until she reaches 17. Aces count as 1 or 11.\n\nYour stack is: {}".format(player_chips.total))
    take_bet(player_chips)

    deck = Deck()
    deck.shuffle()

    dealer_hand = Hand()
    player_hand = Hand()

    for i in range(2):
      dealer_hand.add_card(deck.deal())
      player_hand.add_card(deck.deal())

    show_some(player_hand, dealer_hand) # Show cards (but keep one dealer card hidden)
    keep_playing=True
    while (keep_playing):  # recall this variable from our hit_or_stand function

       keep_playing=hit_or_stand(deck, player_hand)
       print("keep_playing: {}\n".format(keep_playing))
       show_some(player_hand, dealer_hand) # Show cards (but keep one dealer card hidden)

       # If player's hand exceeds 21, run player_busts() and break out of loop
       if player_hand.value>21 :       
          player_busts(player_hand, dealer_hand, player_chips)
          break

    if player_hand.value <= 21:
        
        while dealer_hand.value <= 17:
            hit(deck,dealer_hand)
            
        # Show all cards
        show_all(player_hand,dealer_hand)
        
        # Test different winning scenarios
        if dealer_hand.value > 21:
            dealer_busts(player_hand,dealer_hand,player_chips)

        elif dealer_hand.value > player_hand.value:
            dealer_wins(player_chips)

        elif dealer_hand.value < player_hand.value:
            player_wins(player_chips)

        else:
            push()

           # Inform Player of their chips total    
    print("\nYour current stack: {}\n".format(player_chips.total))
    # Ask to play again
    new_game = input("Would you like to play another hand? Enter 'y' or 'n' ")
    
    if new_game[0].lower()=='y':
        keep_playing=True
        continue
    else:
        print("Thanks for playing!")
        break