-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.py
More file actions
28 lines (23 loc) · 850 Bytes
/
deck.py
File metadata and controls
28 lines (23 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from Cards.card import Card
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
import os
class Deck:
def __init__(self, decklist):
self.cards = []
if type(decklist) == str:
self.load_from_string(decklist)
else:
raise ValueError('given decklist is not a string, received instead:'
' {}'.format(decklist))
def load_from_string(self, decklist_name):
self.cards = []
decklist_location = 'Decklists/' + decklist_name
stream = file(decklist_location,'r')
decklist_dict = load(stream, Loader)
for card_name, number in decklist_dict.iteritems():
for _ in range(number):
self.cards.append(Card(card_name))