first stable version

This commit is contained in:
2018-06-01 18:17:10 +08:00
parent 152a71ff05
commit 4e8525f4cf
5 changed files with 737 additions and 595 deletions

53
game.py
View File

@@ -8,13 +8,15 @@ class Player:
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.status = -1
self.life = 15
self.poison = 0
self.damage = 0 # 因為反制要拿來判斷掃射
self.playing = False
self.attacking = False
self.robbing = False
self.robbing = "0"
self.planning = [] # data temp for plan
self.trading = "0" # data temp for trade
self.surprise = False # 又是因為反制要判斷奇襲
self.turn = 0
@@ -27,18 +29,17 @@ class Player:
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])
try:
self.hand.remove(id)
except:
print("rob except:", id, self.hand)
def defence(self): # to decide if player is able to defend or not
for c in self.hand:
if c in card.unattackable:
@@ -65,7 +66,7 @@ def display(player):
def draw(player): # 抽卡
if len(player.deck) == 0:
player.life = -99999999 # 牌抽乾了就讓他死
return dumps({"msg": "noCard", "data": [player.name]})
return False
new = random.choice(player.deck)
player.add_card(new)
@@ -73,37 +74,3 @@ def draw(player): # 抽卡
# turn control
# cur:current player
# ene:enemy
async def turn(wsp1,wsp2):
p1, p2 = wsp1.player, wsp2.player
wscur, wsene = (wsp1, wsp2) if p1.playing == True else (wsp2, wsp1)
cur, ene = wscur.player, wsene.player
cur.turn += 1
await wscur.send("{} 的第{}回合".format(cur.name,cur.turn))
if cur.poison_check():
await wscur.send("{} 受到了劇毒的侵蝕".format(cur.name))
await wscur.send("{} 損失{}點生命".format(cur.name,cur.poison))
if cur.life <= 0:
return
await sendTo(health(p1,p2), wsp1, wsp2)
await sendTo(draw(cur), wsp1, wsp2) # 抽卡
await sendTo(display(cur), wscur) # 顯示手牌
while True:
await sendTo("請問要使用手牌嗎? 若不使用請輸入0", wscur)
print("Wait receive")
choice = await wscur.recv()
print("Received")
if choice in cur.hand:
card.skills[choice](wscur, wsene)
cur.remove_card(choice)
break
elif choice == "0":
break
elif choice == "-1":
cur.surrender()
await sendTo("{}投降".format(cur.name), wsp1, wsp2)
break
del choice # prevent reading old data
p1.playing,p2.playing = p2.playing,p1.playing # switch!