游戏可以运行
This commit is contained in:
26
card_game/deck.py
Normal file
26
card_game/deck.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Deck class: build, shuffle, draw."""
|
||||
|
||||
import random
|
||||
from card_game.card import Card
|
||||
|
||||
|
||||
class Deck:
|
||||
def __init__(self):
|
||||
self.cards = []
|
||||
self.draw_pile = []
|
||||
|
||||
def build(self, card_id_list):
|
||||
self.cards = [Card(cid) for cid in card_id_list]
|
||||
self.draw_pile = list(self.cards)
|
||||
random.shuffle(self.draw_pile)
|
||||
|
||||
def draw(self):
|
||||
if not self.draw_pile:
|
||||
return None
|
||||
return self.draw_pile.pop()
|
||||
|
||||
def is_empty(self):
|
||||
return len(self.draw_pile) == 0
|
||||
|
||||
def remaining(self):
|
||||
return len(self.draw_pile)
|
||||
Reference in New Issue
Block a user