New.EoD/Game.py
2018-08-26 22:51:31 +08:00

60 lines
2.4 KiB
Python

import Player, Card
class Game:
def __init__(self, first, second):
self.first, self.second = first, second
self.first.draw(3)
self.second.draw(3)
self.turn = 0
def main(self):
while self.first.hp > 0 and self.second.hp > 0:
self.turn += 1
# Poison Check
if self.first.poison:
print("{}因劇毒損失了{}".format(self.first.name, self.first.poison))
self.first.inc_hp(0-self.first.poison)
if self.first.hp <= 0:
print("{}倒下ㄌ".format(self.first.name))
break
print("========Turn {} {}========".format(self.turn//2+1, "先攻" if self.turn%2 else "後攻"))
draw = self.first.draw()
if not draw:
print("{}抽到了死神 吧".format(self.first.name))
self.first.inc_hp(-999) # 讓他死啦
break
print("玩家{}\n{}抽到了{}\n這是{}現在的手牌:".format(self.first, self.first.name, draw, self.first.name))
for i, card in enumerate(self.first.hand):
print(i, ": ", card, sep="")
# Use Cards
while 1:
use = input("請出牌的啦(type p or pass to skip turn): ")
if use == "pass" or use == "p":
print("pass")
break
try:
card = self.first.hand[int(use)]
if isinstance(card, Card.ATKCard):
# Defence Handle
if self.second.defend(card, self.first):
print("防禦成功~")
self.first.hand.remove(card)
break
elif isinstance(card, Card.DEFCard):
print("防禦類卡片無法主動打出")
continue
self.first.hand.pop(int(use)).active(self.first, self.second)
break
except IndexError:
print("索引錯誤")
except ValueError:
print("請輸入數字")
self.first, self.second = self.second, self.first
self.end()
def end(self):
winner = self.second if self.first.hp <= 0 else self.first
print("{}贏了".format(winner.name))
game = Game(Player.Keieit(), Player.Rabbit())
game.main()