New.EoD/Game.py

71 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Player, Card
from random import shuffle
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:
# 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 "後攻"))
self.turn += 1
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):
# Defense Handle
if self.second.defend(card, self.first):
print("防禦成功~")
self.first.hand.remove(card)
break
if self.first.boost > 0 and not isinstance(card, Card.Rob):
self.first.hand[int(use)].damage += 1
print("傷害將會+1效果持續{}回合".format(self.first.boost))
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
# Player Ability Handling
self.first.guard -= 1
self.first.boost -= 1
self.end()
def end(self):
winner = self.second if self.first.hp <= 0 else self.first
print("{}贏了".format(winner.name))
if __name__ == "__main__":
players = [Player.Keieit(), Player.Rabbit()]
shuffle(players)
game = Game(*players)
game.main()