import copy import random import cards from observable import Observable class Game: def __init__(self): self.players = [] class Player: def __init__(self, name, deck=None): self.name = name self.deck = None self.setDeck(deck) def __repr__(self): return 'Player: {0} [Deck:{1}]'.format(self.name, len(self.deck)) def setDeck(self, deck): if not deck: return self.deck = copy.copy(deck) for card in deck: card.owner = self class Card: def __init__(self, name, attributes, cost, power, toughness, owner=None): self.name = name self.attributes = [a.lower() for a in attributes] self.cost = cost self.power = power self.toughness = toughness self.owner = owner # Events self.moved = Observable() self.tapped = Observable() self.attacked = Observable() self.store() def __repr__(self): return 'Card: [{2}] {0}: {1} [{3}/{4}]'.format(self.name, ' '.join([a.capitalize() for a in self.attributes]), self.cost, self.power, self.toughness) def store(self): self.__stored = copy.copy(self) def restore(self): self = copy.copy(self.__stored) def tap(self): self.tapped.emit() class Ability: def __init__(self, target): self.target = target self.init() def init(self): pass class CardList(list): def __init__(self, game): list.__init__(self) self.game = game def append(self, item): item.list = self list.append(self, item) class Deck(CardList): def __init__(self): pass def shuffle(self): random.shuffle(self) def cards(self): return self.__cards if __name__ == '__main__': game = Game() deck = Deck(game) deck.append(Card('Test', ['elf', 'warrior'], '1G', '1', '1')) deck.append(cards.Elvish_Archdruid()) player = Player('Correl', deck) print player print deck