diff --git a/game.py b/game.py index 0b0633d..23c1e0b 100644 --- a/game.py +++ b/game.py @@ -1,5 +1,6 @@ from enum import Enum from random import shuffle +from json import JSONEncoder class BridzikException(Exception): pass @@ -51,7 +52,7 @@ class Card_values(Enum): return NotImplemented -class Card(): +class Card(JSONEncoder): def __init__(self, color: Card_colors, value: Card_values): self.color = color self.value = value @@ -68,6 +69,16 @@ class Card(): def __repr__(self): return ''.format(self.color.name, self.value.name) + class JSONEncoder(JSONEncoder): + def default(self, obj): + if isinstance(obj, Card): + return { + 'color': obj.color.name, + 'value': obj.value.name + } + return JSONEncoder.default(self, obj) + + cards = [Card(color, value) for value in Card_values for color in Card_colors] # for series_number in range(4): # 4 hry