Advertisement
Guest User

Untitled

a guest
May 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.61 KB | None | 0 0
  1. import random
  2.  
  3. #######
  4.  
  5. ace = 11
  6. king = 10
  7. queen = 10
  8. jack = 10
  9. ten = 10
  10.  
  11. deck = [ace,king,queen,jack,ten,9,8,7,6,5,4,3,2]
  12.  
  13.  
  14. #######
  15.  
  16. def Menu():
  17.         print("=== Menu ===")
  18.         print("Type 'play' to play BlackJack!")
  19.         print("Type 'balance' to check your balance!")
  20.         print("Type 'stats' to view your wins and losses!")
  21.         answer = input("")
  22.         return answer
  23.  
  24. class Bank:
  25.     def __init__(self,money = 0):
  26.         self.money = money
  27.     def __repr__(self):
  28.         return ("Money: " + self.money)
  29.     def checkbal(self):
  30.         return ("\nYou have a balance of: $" + str(self.money) + "\n")
  31.  
  32.  
  33.  
  34. a = Bank(1000)
  35.        
  36. #bet = input("How much would you like to bet: $")
  37.  
  38.  
  39. wins = 0
  40. losses = 0
  41.  
  42. class BlackJack:
  43.     def __init__(self):
  44.         self.cardthree = 0
  45.         self.cardtwo = random.choice(deck)
  46.         self.cardone = random.choice(deck)
  47.         self.total = (self.cardone + self.cardtwo)
  48.    
  49.     def __repr__(self):
  50.         return ("Cards drawn: " + str(self.cardone) + " and " + str(self.cardtwo))
  51.    
  52.     def hit(self):
  53.         self.cardthree = random.choice(deck)
  54.         self.total += self.cardthree
  55.         return self.cardthree
  56.  
  57.     def total(self):
  58.         return self.total
  59.  
  60.     def dealer_check(self):
  61.         return ("Dealer drew: " + str(dealer.hit()) + "\nDealer total is: " + str(dealer.total))
  62.  
  63. #######
  64.  
  65.  
  66. def Game():
  67.     while True:
  68.        
  69.     #######
  70.        
  71.         print("\n============= You Go First ! =============\n")
  72.        
  73.         player = BlackJack()
  74.        
  75.         dealer = BlackJack()
  76.    
  77.     #######
  78.        
  79.         print(player)   # Prints user cards
  80.        
  81.         print("Your total is: " + str(player.total))  # Prints total cards user has before hit/pass
  82.        
  83.         hitorpass = input("Would you like to hit or pass: ")
  84.         hitorpass = hitorpass.upper()
  85.        
  86.        
  87.         while True:
  88.             if hitorpass == "HIT":
  89.                 print("Your next card is " + str(player.hit()))   # Draws user new card
  90.                 print("Your total is: " + str(player.total))
  91.                 if player.total < 21:
  92.                     hitorpass = input("Would you like to hit or pass: ")
  93.                     hitorpass = hitorpass.upper()
  94.                 else:
  95.                     print("\nYou Busted! The Dealer Wins!")
  96.                     break
  97.             elif hitorpass == "1":
  98.                 break
  99.             else:
  100.                 print("\n============= Dealer's Turn! =============\n")
  101.                 break
  102.         if hitorpass == "1":
  103.             break
  104.        
  105.        
  106.         if player.total < 22:
  107.             print(dealer)
  108.             print("Dealer total is: " + str(dealer.total))
  109.        
  110.         while dealer.total < 22 and dealer.total <= player.total and player.total < 22:
  111.             while dealer.total <= player.total:
  112.                 print(dealer.dealer_check())
  113.        
  114.         if dealer.total < 22 and dealer.total > player.total and player.total < 22:
  115.             print("\nThe Dealer Has Won!")
  116.             losses += 1
  117.         elif player.total >= 22:
  118.             ""
  119.             losses += 1
  120.         elif dealer.total >= 22:
  121.             print("\nThe Dealer Busted! You Win!")
  122.             wins += 1
  123.         else:
  124.             print("\nYou won!")
  125.             wins += 1
  126.         print("\n\n=============   New Game !   =============\n               Type 1 to Quit")
  127.  
  128. #######
  129.  
  130.  
  131. while True:
  132.     choice = Menu()
  133.     if choice == "play":
  134.         Game()
  135.     elif choice == "balance":
  136.         print(a.checkbal())
  137.     elif choice == "stats":
  138.         print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement