Files
mau/deck.py
T
2024-05-12 20:23:34 +01:00

40 lines
1.0 KiB
Python

from card import card
import random
class deck:
def __init__(self):
self.cards = []
self.build()
self.discard_pile = []
def build(self):
for suit in ["Spades", "Hearts", "Diamonds", "Clubs"]:
for value in range(1, 14):
self.cards.append( card(value, suit) )
def show(self):
for card in self.cards:
print(card)
def shuffle(self):
if len(self.cards) > 0:
print('grabbing the remaining cards from the deck')
self.discard_pile.extend(self.cards)
print('shuffling the deck')
self.cards = self.discard_pile
random.shuffle(self.cards)
self.discard_pile = []
return self.cards
def check_empty(self):
if len(self.cards) == 0:
return True
else:
return False
def first_card(self):
# adds the top deck card to the top of the discard pile
self.discard_pile.append(self.cards.pop())
return self