more elegant setup function

This commit is contained in:
Bibin Muttappillil 2020-04-15 14:20:30 +02:00
parent caca8bc2e5
commit be93817063
2 changed files with 16 additions and 7 deletions

View File

@ -36,15 +36,18 @@ class Game:
def setup(self): def setup(self):
self.role = dict() self.role = dict()
# setting default value
for r in Role.__subclasses__(): 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) r(self)
self.role[Werewolf] = []
self.role[Mason] = []
self.voting_list = self.player_list + [No_player()] self.voting_list = self.player_list + [No_player()]
for c in self.voting_list: for c in self.voting_list:
c.tally = 0 c.reset()
c.won = c.dead = False self.time = 0
def distribute_roles(self): def distribute_roles(self):
shuffle(self.role_list) shuffle(self.role_list)
@ -74,6 +77,9 @@ class Game:
async def start_day(self): async def start_day(self):
await self.send("The day has started") await self.send("The day has started")
async def discussion_timer(self):
pass
async def vote(self): async def vote(self):
# vote # vote
@ -168,8 +174,8 @@ class Game:
async def round(self): async def round(self):
try: try:
self.check() self.check()
self.running = True
self.setup() self.setup()
self.running = True
self.distribute_roles() self.distribute_roles()
await self.start_night() await self.start_night()
await self.send_role() await self.send_role()
@ -177,7 +183,6 @@ class Game:
await self.night_phases() await self.night_phases()
await self.start_day() await self.start_day()
# discussion timer
await self.vote() await self.vote()
self.tally() self.tally()

View File

@ -14,6 +14,10 @@ class Player:
def setRole(self, role): def setRole(self, role):
self.day_role = self.night_role = role self.day_role = self.night_role = role
def reset(self):
self.tally = 0
self.won = self.dead = False
def name(self): def name(self):
return self.member.name return self.member.name