initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user