summaryrefslogtreecommitdiff
path: root/swiftstory/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'swiftstory/client.py')
-rw-r--r--swiftstory/client.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/swiftstory/client.py b/swiftstory/client.py
index 9ac08ed..98ba530 100644
--- a/swiftstory/client.py
+++ b/swiftstory/client.py
@@ -5,6 +5,7 @@ from typing import Optional
import websockets.exceptions
from swiftstory.game import Game
+from swiftstory.game_manager import GameManager
from swiftstory.exception import WrongAction, UnsupportedLanguage, JoinError
from swiftstory.player import Player
@@ -13,14 +14,14 @@ 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):
+ def __init__(self, socket, game_manager: GameManager) -> None:
self.game: Optional[Game] = None
- self.game_manager = game_manager
+ self.game_manager: GameManager = game_manager
self.socket = socket
self.player: Optional[Player] = None
- def join_game(self, game_name, lang) -> str:
+ def join_game(self, game_name: str, lang: Optional[str]) -> str:
if self.game is not None:
raise WrongAction('You are already in a game')
@@ -39,39 +40,53 @@ class Client:
return status
- def play_white_card(self, card_id):
+ def play_white_card(self, card_id: int) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_play_card(self.player, card_id)
- def pick_black_card(self):
+ def pick_black_card(self) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_become_judge(self.player)
- def collect_cards(self):
+ def collect_cards(self) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_collect_cards(self.player)
- def designate_card(self, card_id):
+ def designate_card(self, card_id: int) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_designate_card(self.player, card_id)
- def view_player_cards(self):
+ def view_player_cards(self) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_view_player_cards(self.player)
- def view_played_cards(self):
+ def view_played_cards(self) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_view_played_cards(self.player)
- def view_black_card(self):
+ def view_black_card(self) -> str:
if self.game is None:
raise WrongAction('You have to join a game first')
+ if self.player is None:
+ raise ValueError("Player is None")
return self.game.try_view_black_card(self.player)
def monitor_player(self) -> None:
@@ -87,7 +102,7 @@ class Client:
asyncio.create_task(f())
- def disconnect(self):
+ def disconnect(self) -> None:
if self.player is not None:
if self.game is None:
raise ValueError("Disconnect from inexistent game.")