Initial commit
This commit is contained in:
commit
228848b113
4 changed files with 105 additions and 0 deletions
4
abilities.py
Normal file
4
abilities.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import mtg
|
||||||
|
|
||||||
|
class Lifelink(mtg.Ability):
|
||||||
|
pass
|
14
cards.py
Normal file
14
cards.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from mtg import *
|
||||||
|
"""
|
||||||
|
Elvish Archdruid
|
||||||
|
1GG
|
||||||
|
Creature -- Elf Druid
|
||||||
|
2/2
|
||||||
|
Other Elf creatures you control get +1/+1.
|
||||||
|
{T}: Add {G} to your mana pool for each Elf you control.
|
||||||
|
M10-R
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Elvish_Archdruid(Card):
|
||||||
|
def __init__(self):
|
||||||
|
Card.__init__(self, 'Elvish Archdruid', ['elf', 'druid'], '1GG', 2, 2)
|
79
mtg.py
Normal file
79
mtg.py
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
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
|
8
observable.py
Normal file
8
observable.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class Observable(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.subscribers = []
|
||||||
|
def subscribe(self, subscriber):
|
||||||
|
self.subscribers.append(subscriber)
|
||||||
|
def emit(self, *args):
|
||||||
|
for fn in self.subscribers:
|
||||||
|
fn(*args)
|
Loading…
Reference in a new issue