diff options
Diffstat (limited to 'swiftstory/client.py')
-rw-r--r-- | swiftstory/client.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/swiftstory/client.py b/swiftstory/client.py index 437a3f9..9ac08ed 100644 --- a/swiftstory/client.py +++ b/swiftstory/client.py @@ -6,17 +6,21 @@ import websockets.exceptions from swiftstory.game import Game from swiftstory.exception import WrongAction, UnsupportedLanguage, JoinError +from swiftstory.player import Player class Client: + """ Represent a client. + A client manages a (web)socket to communicate with the outside world. + It also manages the associated player when in a game. """ def __init__(self, socket, game_manager): self.game: Optional[Game] = None self.game_manager = game_manager self.socket = socket - self.player = None + self.player: Optional[Player] = None - def join_game(self, game_name, lang): + def join_game(self, game_name, lang) -> str: if self.game is not None: raise WrongAction('You are already in a game') @@ -27,9 +31,13 @@ class Client: game = self.game_manager.find_by_name(game_name, lang) except UnsupportedLanguage as e: raise JoinError(f"unsupported language: {str(e)}") from e - # XXX self.game will be assigned by game.try_join() - return game.try_join(self) + self.player = Player() + status = game.try_join(self.player) + self.game = game + self.monitor_player() + + return status def play_white_card(self, card_id): if self.game is None: |