New.EoD/Game.py
2018-08-26 19:07:59 +08:00

40 lines
1.5 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)
def main(self):
while self.first.hp > 0 and self.second.hp > 0:
print("輪到{}\n{}抽到了{}\n這是{}現在的手牌:".format(self.first.name, self.first.name, self.first.draw(), self.first.name))
for i, card in enumerate(self.first.hand):
print(i, ": ", card, sep="")
# Use Cards
while 1:
use = input("請出牌的啦")
try:
card = self.first.hand[int(use)]
if isinstance(card, Card.ATKCard):
# Defence Handle
if self.second.defend(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()