Main game function modified, turn bug fixed

This commit is contained in:
Jerry Wu 2018-08-27 11:22:43 +08:00
parent cdc475ecc4
commit 532045a6ba

10
Game.py
View File

@ -1,4 +1,5 @@
import Player, Card import Player, Card
from random import shuffle
class Game: class Game:
def __init__(self, first, second): def __init__(self, first, second):
@ -8,7 +9,6 @@ class Game:
self.turn = 0 self.turn = 0
def main(self): def main(self):
while self.first.hp > 0 and self.second.hp > 0: while self.first.hp > 0 and self.second.hp > 0:
self.turn += 1
# Poison Check # Poison Check
if self.first.poison: if self.first.poison:
print("{}因劇毒損失了{}".format(self.first.name, self.first.poison)) print("{}因劇毒損失了{}".format(self.first.name, self.first.poison))
@ -17,6 +17,7 @@ class Game:
print("{}倒下ㄌ".format(self.first.name)) print("{}倒下ㄌ".format(self.first.name))
break break
print("========Turn {} {}========".format(self.turn//2+1, "先攻" if self.turn%2 else "後攻")) print("========Turn {} {}========".format(self.turn//2+1, "先攻" if self.turn%2 else "後攻"))
self.turn += 1
draw = self.first.draw() draw = self.first.draw()
if not draw: if not draw:
print("{}抽到了死神 吧".format(self.first.name)) print("{}抽到了死神 吧".format(self.first.name))
@ -66,5 +67,8 @@ class Game:
winner = self.second if self.first.hp <= 0 else self.first winner = self.second if self.first.hp <= 0 else self.first
print("{}贏了".format(winner.name)) print("{}贏了".format(winner.name))
game = Game(Player.Keieit(), Player.Rabbit()) if __name__ == "__main__":
game.main() players = [Player.Keieit(), Player.Rabbit()]
shuffle(players)
game = Game(*players)
game.main()