From be93817063bf907bd071f64187422db02cad1b66 Mon Sep 17 00:00:00 2001 From: bibin Date: Wed, 15 Apr 2020 14:20:30 +0200 Subject: [PATCH] more elegant setup function --- src/werewolf_game.py | 19 ++++++++++++------- src/werewolf_players.py | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/werewolf_game.py b/src/werewolf_game.py index 4f5388f..6ba781d 100644 --- a/src/werewolf_game.py +++ b/src/werewolf_game.py @@ -36,15 +36,18 @@ class Game: def setup(self): self.role = dict() + # setting default value for r in Role.__subclasses__(): - if r not in [Werewolf, Mason, No_role]: + if r == No_role: + continue + if r in [Werewolf, Mason]: + self.role[r] = [] + else: r(self) - self.role[Werewolf] = [] - self.role[Mason] = [] self.voting_list = self.player_list + [No_player()] for c in self.voting_list: - c.tally = 0 - c.won = c.dead = False + c.reset() + self.time = 0 def distribute_roles(self): shuffle(self.role_list) @@ -74,6 +77,9 @@ class Game: async def start_day(self): await self.send("The day has started") + async def discussion_timer(self): + pass + async def vote(self): # vote @@ -168,8 +174,8 @@ class Game: async def round(self): try: self.check() - self.running = True self.setup() + self.running = True self.distribute_roles() await self.start_night() await self.send_role() @@ -177,7 +183,6 @@ class Game: await self.night_phases() await self.start_day() - # discussion timer await self.vote() self.tally() diff --git a/src/werewolf_players.py b/src/werewolf_players.py index 5c7f89e..8d4fd1c 100644 --- a/src/werewolf_players.py +++ b/src/werewolf_players.py @@ -14,6 +14,10 @@ class Player: def setRole(self, role): self.day_role = self.night_role = role + def reset(self): + self.tally = 0 + self.won = self.dead = False + def name(self): return self.member.name