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 @dataclass
class RoundVote: class RoundVote:
player1: Player player1: Player
player2: Player | None player2: Player | None = None
vote: Vote vote: Vote | None = None
timestamp: datetime timestamp: datetime | None = None
@property @property
def players(self): def players(self):
@ -116,6 +116,23 @@ class Game:
self.players[name] = player self.players[name] = player
return 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: def save(self, filename: str) -> None:
""" """
Uses pickle to save the current state of the game. 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.register_player(player.name, config.vote_channels[player.name.lower()])
GAME.save('game.save') 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: if not config.telepathy_channel:
channel: TextChannel = await secret_category.create_text_channel("bigbrain") channel: TextChannel = await secret_category.create_text_channel("bigbrain")
config.telepathy_channel = channel.id config.telepathy_channel = channel.id