summaryrefslogtreecommitdiff
path: root/swiftstory/client.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 22:49:35 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 23:15:21 +0100
commite9faa90b9e3c8138b5d4763a2d8279f61486238c (patch)
treecf8e4dc745caaf3f2da780a8c5e471ef10a13a73 /swiftstory/client.py
parent041f3e63118837acaa2316139dd9ca6c796a79e6 (diff)
Avoid dependency on Client from Game
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/client.py')
-rw-r--r--swiftstory/client.py16
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: