forked from zefanye/sanguosha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.py
206 lines (178 loc) · 8.19 KB
/
card.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import player
import global_var
def action_default(self_card, player):
print("This is the default action for")
self_card.show()
return True
class card:
def __init__(self, cat, s, n, na, ec="", r="", tc="", e="", d="", i="", action=action_default):
self.category=cat
self.suit=s
self.number=n
self.name=na
self.description=d
self.image=i
self.element=e
self.equipment_category=ec
self.range=r
self.tips_category=tc
self.action=action
def show(self):
element_str =""
if self.element != "":
element_str=self.element+"-"
equipment_category_str=""
if self.equipment_category != "":
equipment_category_str="("+self.equipment_category
if self.equipment_category=="weapons":
equipment_category_str += self.range
equipment_category_str += ")"
tc_str=""
if self.tips_category !="":
tc_str=self.tips_category+"-"
print("This is card:", element_str+self.name, "["+self.suit, self.number, tc_str+self.category+equipment_category_str, self.description, self.image+"]")
def play(self, self_player:player):
#if self.name=="something from nothing":
# print("Play something from nothing")
# for i in range(2):
# self_player.draw_cards()
return self.action(self, self_player)
def shuffle(cards_to_shuffle):
import random
copied_cards=cards_to_shuffle.copy()
s=[]
#print(len(cards_to_shuffle))
for i in range(len(copied_cards)):
randomCards=random.randint(0,len(copied_cards)-1)
#print(randomCards)
s.append(copied_cards[randomCards])
del copied_cards[randomCards]
return s
##############################################
# Define all card actions here
# All card actions must accept two parameters:
# self_card: the card that has the action
# player: the player who play the card
def action_something_from_nothing(self_card, player):
for i in range(2):
player.draw_cards()
return True
def action_attack(self_card, player):
live_players=global_var.get_live_players()
target=int(input("Which player are you attacking? "))
if target>=len(live_players):
print("player does not exist")
target_player=global_var.get_live_players()[target]
def action_peach(self_card, player):
succesful=player.restore_health()
return succesful
def add_all_cards():
#card1=card("basic","hearts","9","peach")
#card2=card("tips","spades","A","lightning")
global all_cards
all_cards.append(card("equipment","spades","K","da_wuan","-1 horse"))
all_cards.append(card("tips","spades","J","steal"))
all_cards.append(card("basic","spades","5","attack",e="thunder"))
all_cards.append(card("tips","spades","A","lightning",tc="delayed"))
all_cards.append(card("basic","hearts","2","dodge"))
all_cards.append(card("basic","hearts","9","peach", action=action_peach))
all_cards.append(card("equipment","diamonds","A","fan","weapons","4"))
all_cards.append(card("tips","clubs","Q","unbreakable"))
all_cards.append(card("equipment","spades","5","dragon blade","weapons","3"))
all_cards.append(card("tips","spades","7","barbarian invasion"))
all_cards.append(card("equipment","heart","5","red rabbit","-1 horse" ))
all_cards.append(card("basic","diamonds","7","dodge"))
all_cards.append(card("tips","spades","K","barbarian invasion"))
all_cards.append(card("basic","clubs","8","attack"))
all_cards.append(card("equipment","hearts","5","kirin bow","weapons","5"))
all_cards.append(card("basic","diamonds","2","dodge"))
all_cards.append(card("tips","hearts","A","brotherhood"))
all_cards.append(card("equipment","spades","5","jue ying","+1 horse"))
all_cards.append(card("tips","hearts","9","something from nothing", action=action_something_from_nothing))
all_cards.append(card("tips","spades","3","steal"))
all_cards.append(card("equipment","spades","2","masculine feminine double wielded swords","weapons","2"))
all_cards.append(card("basic","hearts","6","peach", action=action_peach))
all_cards.append(card("basic","hearts","10","attack"))
all_cards.append(card("tips","diamonds","3","steal"))
all_cards.append(card("basic","diamonds","6","dodge"))
all_cards.append(card("basic","hearts","2","dodge"))
all_cards.append(card("tips","clubs","Q","unbreakable"))
all_cards.append(card("tips","clubs","A","duel"))
all_cards.append(card("basic","diamonds","K","attack"))
all_cards.append(card("tips","spades","6","enprisoned"))
all_cards.append(card("equipment","clubs","A","silver lion helmet"))
all_cards.append(card("basic","spades","3","wine"))
all_cards.append(card("basic","diamonds","7","dodge"))
all_cards.append(card("equipment","diamonds","K","hua liu"))
all_cards.append(card("basic","hearts","9","peach", action=action_peach))
all_cards.append(card("basic","clubs","8","attack"))
all_cards.append(card("basic","diamonds","9","attack"))
all_cards.append(card("basic","diamonds","Q","peach", action=action_peach))
all_cards.append(card("tips","clubs","4","discard"))
all_cards.append(card("basic","clubs","J","attack"))
all_cards.append(card("basic","spades","7","attack"))
all_cards.append(card("tips","clubs","Q","borrow weapon"))
all_cards.append(card("tips","hearts","4","harvest"))
all_cards.append(card("basic","hearts","2","dodge"))
all_cards.append(card("basic","diamonds","J","dodge"))
all_cards.append(card("basic","hearts","4","attack",e="fire"))
all_cards.append(card("tips","hearts","9","something from nothing"))
all_cards.append(card("tips","spades","3","discard"))
all_cards.append(card("equipment","diamonds","Q","attack"))
all_cards.append(card("tips","hearts","Q","discard"))
all_cards.append(card("tips","diamonds","Q","fire attack"))
all_cards.append(card("basic","diamonds","Q","peach", action=action_peach))
all_cards.append(card("tips","diamonds","Q","unbreakable"))
all_cards.append(card("basic","diamonds","K","attack"))
all_cards.append(card("equipment","diamonds","K","purple_horse","-1 horse"))
all_cards.append(card("equipment","diamonds","A","zhuge_crossbow","weapons","1"))
all_cards.append(card("basic","diamonds","2","dodge"))
all_cards.append(card("equipment","spades","2","bagua_array"))
all_cards.append(card("basic","diamonds","2","peach", action=action_peach))
all_cards.append(card("equipment","clubs","2","bagua_array"))
all_cards.append(card("equipment","spades","6","qing_gang_sword","weapons","2"))
all_cards.append(card("basic","hearts","J","dodge"))
all_cards.append(card("basic","diamonds","2","peach", action=action_peach))
all_cards.append(card("basic","diamonds","4","dodge"))
all_cards.append(card("tips","hearts","Q","lightning",tc="delayed"))
all_cards.append(card("basic","hearts","9","peach"))
all_cards.append(card("tips","spades","4","attack",e="thunder"))
all_cards.append(card("basic","clubs","2","attack"))
all_cards.append(card("basic","clubs","5","attack",e="thunder"))
all_cards.append(card("tips","hearts","K","unbreakable"))
all_cards.append(card("tips","hearts","6","banished",tc="delayed"))
all_cards.append(card("tips","clubs","K","borrow weapon"))
return
all_cards = []
card_stack = []
discard_pile=all_cards
def extract_card_from_stack():
global card_stack
global discard_pile
if len(card_stack)==0:
card_stack=shuffle(discard_pile)
discard_pile=[]
# discard_pile need to be emptied here!!!
cards=card_stack[0]
del card_stack[0]
return cards
def discard_card(c):
global discard_pile
discard_pile.append(c)
def card_type_bank():
pass
def init():
add_all_cards()
global card_stack
card_stack = shuffle(all_cards)
card_stack.insert(0, card("basic","diamonds","2","peach", action=action_peach))
#for c in card_stack:
# c.show()
def main():
init()
for i in range(100):
c = extract_card_from_stack()
c.show()
discard_card(c)
if __name__ == "__main__":
main()