Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #######
- ace = 11
- king = 10
- queen = 10
- jack = 10
- ten = 10
- deck = [ace,king,queen,jack,ten,9,8,7,6,5,4,3,2]
- #######
- def Menu():
- print("=== Menu ===")
- print("Type 'play' to play BlackJack!")
- print("Type 'balance' to check your balance!")
- print("Type 'stats' to view your wins and losses!")
- answer = input("")
- return answer
- class Bank:
- def __init__(self,money = 0):
- self.money = money
- def __repr__(self):
- return ("Money: " + self.money)
- def checkbal(self):
- return ("\nYou have a balance of: $" + str(self.money) + "\n")
- a = Bank(1000)
- #bet = input("How much would you like to bet: $")
- wins = 0
- losses = 0
- class BlackJack:
- def __init__(self):
- self.cardthree = 0
- self.cardtwo = random.choice(deck)
- self.cardone = random.choice(deck)
- self.total = (self.cardone + self.cardtwo)
- def __repr__(self):
- return ("Cards drawn: " + str(self.cardone) + " and " + str(self.cardtwo))
- def hit(self):
- self.cardthree = random.choice(deck)
- self.total += self.cardthree
- return self.cardthree
- def total(self):
- return self.total
- def dealer_check(self):
- return ("Dealer drew: " + str(dealer.hit()) + "\nDealer total is: " + str(dealer.total))
- #######
- def Game():
- while True:
- #######
- print("\n============= You Go First ! =============\n")
- player = BlackJack()
- dealer = BlackJack()
- #######
- print(player) # Prints user cards
- print("Your total is: " + str(player.total)) # Prints total cards user has before hit/pass
- hitorpass = input("Would you like to hit or pass: ")
- hitorpass = hitorpass.upper()
- while True:
- if hitorpass == "HIT":
- print("Your next card is " + str(player.hit())) # Draws user new card
- print("Your total is: " + str(player.total))
- if player.total < 21:
- hitorpass = input("Would you like to hit or pass: ")
- hitorpass = hitorpass.upper()
- else:
- print("\nYou Busted! The Dealer Wins!")
- break
- elif hitorpass == "1":
- break
- else:
- print("\n============= Dealer's Turn! =============\n")
- break
- if hitorpass == "1":
- break
- if player.total < 22:
- print(dealer)
- print("Dealer total is: " + str(dealer.total))
- while dealer.total < 22 and dealer.total <= player.total and player.total < 22:
- while dealer.total <= player.total:
- print(dealer.dealer_check())
- if dealer.total < 22 and dealer.total > player.total and player.total < 22:
- print("\nThe Dealer Has Won!")
- losses += 1
- elif player.total >= 22:
- ""
- losses += 1
- elif dealer.total >= 22:
- print("\nThe Dealer Busted! You Win!")
- wins += 1
- else:
- print("\nYou won!")
- wins += 1
- print("\n\n============= New Game ! =============\n Type 1 to Quit")
- #######
- while True:
- choice = Menu()
- if choice == "play":
- Game()
- elif choice == "balance":
- print(a.checkbal())
- elif choice == "stats":
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement