-
Notifications
You must be signed in to change notification settings - Fork 32
/
cards.py
114 lines (90 loc) · 3.5 KB
/
cards.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import itertools
class Card:
def __init__(self):
self.mc = {'White': 0, 'Blue': 0, 'Black': 0, 'Red': 0, 'Green': 0, 'Colorless': 0, 'Generic': 0}
self.tapped_abilities = []
self.deck_location_known = False
self.owner = None
self.is_tapped = False
def play(self, owner, game, verbose=False):
self.owner = owner
def __repr__(self):
return self.name
class Land(Card):
def __init__(self, name, types, subtypes, tapped_abilities):
super(Land, self).__init__()
self.name = name
self.types = types
self.subtypes = subtypes
self.tapped_abilities = tapped_abilities
def play(self, owner, game, verbose=False):
super(Land, self).play(owner, game, verbose)
if verbose:
print(" playing %s" % (self.name))
game.battlefield.append(self)
self.owner.can_play_land = False
def use_tapped_ability(self, index):
if not self.is_tapped:
self.is_tapped = True
self.tapped_abilities[index](self)
def __str__(self):
return self.name
class Sorcery(Card):
def __init__(self, name, subtypes, mc):
super(Sorcery, self).__init__()
self.name = name
self.mc = {x: mc.get(x, 0) + self.mc.get(x, 0) for x in set(mc).union(self.mc)}
self.subtypes = subtypes
def play(self, owner, game, verbose=False):
super(Sorcery, self).play(owner, game)
if verbose:
print(" casting %s" % (self.name))
owner.casting_spell = self.name
def __repr__(self):
return self.name
def __str__(self):
return self.name
class Creature(Card):
def __init__(self, name, subtypes, mc, power, toughness, cannot_block=False):
super(Creature, self).__init__()
self.name = name
self.mc = {x: mc.get(x, 0) + self.mc.get(x, 0) for x in set(mc).union(self.mc)}
self.base_power = power
self.power = power
self.base_toughness = toughness
self.toughness = toughness
self.subtypes = subtypes
self.is_dead = False
self.summoning_sick = True
self.damage_taken = 0
self.damage_to_assign = 0
self.is_attacking = []
self.is_blocked_by = []
self.is_blocking = []
self.damage_assignment_order = []
self.damage_assignment = []
# Consider adding a functional creature card instantiation argument that sets text automatically
self.cannot_block = cannot_block
def play(self, owner, game, verbose=False):
super(Creature, self).play(owner, game)
if verbose:
print(" casting %s" % (self.name))
game.battlefield.append(self)
def take_damage(self, amount):
self.damage_taken += amount
if self.damage_taken >= self.toughness:
self.is_dead = True
def deal_combat_damage_to_opponent(self, game):
game.players[1 - self.owner.index].lose_life(self.power)
def set_damage_assignment_order(self, order):
all_permutations = list(itertools.permutations(self.is_blocked_by))
self.damage_assignment_order = list(all_permutations[order])
self.damage_to_assign = self.power
self.damage_assignment = [0] * len(self.damage_assignment_order)
def assign_damage(self, index, amount):
self.damage_assignment[index] += amount
self.damage_to_assign -= amount
def __repr__(self):
return self.name
def __str__(self):
return self.name