Advertisement
Richmondo

Untitled

Dec 11th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1. import random
  2.  
  3. #This will be the base class it will have all of the defining features such as number and set it belongs to.
  4. class Card(object):
  5.     def __init__(self,number,set):
  6.         self.set = set;
  7.         self.number = number;
  8.     def __str__(self):
  9.         Cards = []
  10.         if self.number == 1:
  11.             Cards.append("Ace")
  12.         elif self.number == 11:
  13.             Cards.append("Jack")
  14.         elif self.number == 12:
  15.             Cards.append("Queen")
  16.         elif self.number == 13:
  17.             Cards.append("King")
  18.         else:
  19.             Cards.append(str(self.number))
  20. # This is checking to see if a card has any numbers which would normally be a picture card and changes it to the name of the card.
  21.         if self.set == 0:
  22.             Cards.append("♠")
  23.         elif self.set == 1:
  24.             Cards.append("♥")
  25.         elif self.set == 2:
  26.             Cards.append("♦")
  27.         elif self.set == 3:
  28.             Cards.append("♣")
  29. # This checks which suit the card belongs to and gives the symbol accordingly.
  30.         return Cards
  31.  
  32.     def CardSet(self,set):
  33.         self.set = set
  34.  
  35.     def CardNumber(self,number):
  36.         self.number = number
  37.  
  38. """
  39. This class is going to be the deck so it will have a way to reset the deck which will be drawing cards,
  40. a way to deal and a way to be able to shuffle the deck as well.
  41. """
  42. class Deck(object):
  43.     def __init__(self,cards):
  44.         self.cards = cards;
  45.  
  46.     def __str__(self):
  47.         Cards = []
  48.         for card in self.cards:
  49.             Cards.append(card.__str__())
  50.         Cardstr = " ".join(str(i) for i in Cards)
  51.         return Cardstr
  52.  
  53.     def Reset(self):
  54.         self.cards = []
  55.         for i in range(53):
  56.             if i <= 12:
  57.                 self.cards.append(Card(i+1,0))
  58.             if i > 13 and i <= 26:
  59.                 self.cards.append(Card(i-13,1))
  60.             if i > 26 and i <= 39:
  61.                 self.cards.append(Card(i-26,2))
  62.             if i > 39:
  63.                 self.cards.append(Card(i-39,3))
  64. # The reset function is reseting the deck by putting all cards back into it.
  65.     def Shuffle(self):
  66.         random.shuffle(self.cards)
  67.     def Deal(self,Hand,DrawAmount):
  68.         if len(self.cards) > 0:
  69.             for i in range(DrawAmount):
  70.                 try:
  71.                     Hand.cards.append(self.cards[len(self.cards)-1])
  72.                     self.cards.pop(len(self.cards)-1)
  73.                 except:
  74.                     print("The deck has no more cards in it")
  75.                     break
  76. """
  77. The shuffle function is from the random library and it shuffles the list, to be in a random order.
  78. and the Deal function takes in the amount hand which it needs to draw to and how many cards and then
  79. gives the card to the hand by appending and removes it from the deck by popping it. The error exception then
  80. checks if there is cards to draw and if not it breaks the deal loop.
  81. """
  82.  
  83. #For the hand class it will be pretty simple: a way of reseting the hand for each draw and being able to print the cards in the hand.
  84. class Hand(object):
  85.     def __init__(self,cards):
  86.         self.cards = cards;
  87.  
  88.     def __str__(self):
  89.         Cards = ""
  90.         for card in self.cards:
  91.             Cards += str(card.__str__())
  92.         return Cards
  93.  
  94.     def Reset(self):
  95.         self.cards = []
  96.  
  97. Deck = Deck([])
  98. Hand = Hand([])
  99. # This is making the deck and the Hand, it then resets the deck filling it and shuffles it
  100. Deck.Reset()
  101. Deck.Shuffle()
  102. while True:
  103.     Input = input(str("Would you like to deal a hand? : ").lower())
  104.  
  105.     if len(Deck.cards) <=0:
  106.         Deck.Reset()
  107.         Deck.Shuffle()
  108. #This is checking to see if the deck is empty
  109.     if Input == "yes":
  110.         Hand.Reset()
  111.         Deck.Deal(Hand,5)
  112. # It then resets the hand and the deals 5 from the deck
  113.         Hand1 = Hand
  114.         print(Hand)
  115.     elif Input == "no" or "quit":
  116.         break
  117.     else:
  118.         print("Please either enter yes to deal, or no if you would like to quit!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement