Initialize Game with the first round

This commit is contained in:
Yohann D'ANELLO 2021-11-08 15:13:51 +01:00
parent a072ea3dd0
commit 08d7a50965
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 25 additions and 3 deletions

View File

@ -61,9 +61,9 @@ class Player:
@dataclass
class RoundVote:
player1: Player
player2: Player | None
vote: Vote
timestamp: datetime
player2: Player | None = None
vote: Vote | None = None
timestamp: datetime | None = None
@property
def players(self):
@ -116,6 +116,23 @@ class Game:
self.players[name] = player
return player
def default_first_round(self) -> Round:
return Round(
round=1,
room_a=RoundRoom(room=Room.A,
vote1=RoundVote(player1=GAME.players['Tora']),
vote2=RoundVote(player1=GAME.players['Kamui'],
player2=GAME.players['Philia'])),
room_b=RoundRoom(room=Room.A,
vote1=RoundVote(player1=GAME.players['Dan']),
vote2=RoundVote(player1=GAME.players['Ennea'],
player2=GAME.players['Delphine'])),
room_c=RoundRoom(room=Room.A,
vote1=RoundVote(player1=GAME.players['Hanabi']),
vote2=RoundVote(player1=GAME.players['Nona'],
player2=GAME.players['Oji'])),
)
def save(self, filename: str) -> None:
"""
Uses pickle to save the current state of the game.
@ -227,6 +244,11 @@ async def on_ready():
GAME.register_player(player.name, config.vote_channels[player.name.lower()])
GAME.save('game.save')
# Setup first round if not exists
if not GAME.rounds:
GAME.rounds.append(GAME.default_first_round())
GAME.save('game.save')
if not config.telepathy_channel:
channel: TextChannel = await secret_category.create_text_channel("bigbrain")
config.telepathy_channel = channel.id