This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgame.py
101 lines (90 loc) · 2.88 KB
/
game.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
import random
import card
class Player:
def __init__(self,name,deck):
self.name = name
self.deck = deck[:] # to pass by value instead of by reference
self.hand = []
self.display = [] # names of cards in hand
self.life = 20
self.poison = 0
self.damage = 0 # 因為反制要拿來判斷掃射
self.playing = False
self.attacking = False
self.robbing = False
self.surprise = False # 又是因為反制要判斷奇襲
self.turn = 0
def poison_check(self):
if self.poison != 0:
self.life -= self.poison
return True
else:
return False
def add_card(self,id):
self.hand.append(id)
self.display.append(card.cards[id])
self.deck.remove(id)
def remove_card(self,id):
self.hand.remove(id)
self.display.remove(card.cards[id])
self.deck.append(id)
def robbed(self,id): # be robbed
self.hand.remove(id)
self.display.remove(card.cards[id])
def defence(self): # to decide if player is able to defend or not
for c in self.hand:
if c in card.unattackable:
return True
return False
def keep(self): # to decide if player is able to be robbed or not
for c in self.hand:
if c in card.unrobable:
return True
return False
# game functions
def health(p1,p2):
print("{} 的生命: {}".format(p1.name,p1.life))
print("{} 的生命: {}".format(p2.name,p2.life))
def display(player):
print("這是 {} 的手牌".format(player.name))
print(player.display)
def draw(player): # 抽卡
if len(player.deck) == 0:
player.life = -99999999 # 牌抽乾了就讓他死
print("你抽到了死神")
return None
new = random.choice(player.deck)
print("{} 抽到了 {}".format(player.name,card.cards[new]))
player.add_card(new)
print("牌組剩餘: {} 張".format(len(player.deck)))
# turn control
# cur:current player
# ene:enemy
def turn(p1,p2):
if p1.playing:
cur = p1
ene = p2
elif p2.playing:
cur = p2
ene = p1
cur.turn += 1
print("") # change line
print("{} 的第{}回合".format(cur.name,cur.turn))
if cur.poison_check():
print("{} 受到了劇毒的侵蝕".format(cur.name))
print("{} 損失{}點生命".format(cur.name,cur.poison))
if cur.life <= 0:
return
health(p1,p2)
draw(cur) # 抽卡
display(cur) # 顯示手牌
while True:
choice = input("請問要使用手牌嗎? 若不使用請輸入0 ")
if choice in cur.hand:
card.skills[choice](cur,ene)
cur.remove_card(choice)
break
elif choice == "0":
break
del choice # prevent reading old data
p1.playing,p2.playing = p2.playing,p1.playing # switch!