summaryrefslogtreecommitdiff
path: root/swiftstory/game.py
diff options
context:
space:
mode:
Diffstat (limited to 'swiftstory/game.py')
-rw-r--r--swiftstory/game.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/swiftstory/game.py b/swiftstory/game.py
index 1655d73..4569a5c 100644
--- a/swiftstory/game.py
+++ b/swiftstory/game.py
@@ -1,6 +1,6 @@
from enum import Enum, auto
import random
-from typing import Optional
+from typing import List, Optional, Tuple
from swiftstory.exception import WrongAction, JoinError
from swiftstory.player import Player
@@ -15,11 +15,11 @@ class GameState(Enum):
class Game:
- def __init__(self, white_desc, black_desc):
+ def __init__(self, white_desc: List[str], black_desc: List[str]) -> None:
self.state = GameState.WAITING_NEW_JUDGE
- self.players = []
+ self.players: List[Player] = []
self.judge: Optional[Player] = None
@@ -30,11 +30,11 @@ class Game:
random.shuffle(self.board.white_pick)
random.shuffle(self.board.black_pick)
- def try_join(self, player):
+ def try_join(self, player: Player) -> str:
if len(self.players) >= 10:
raise JoinError('too many players in this game')
- cards = []
+ cards: List[Tuple[int, str]] = []
try:
for _ in range(10):
@@ -63,7 +63,7 @@ class Game:
return success({'cards': cards, 'game_state': state})
- def try_become_judge(self, player):
+ def try_become_judge(self, player: Player) -> str:
if self.state is not GameState.WAITING_NEW_JUDGE:
# TODO what if the judge has quit ?
raise WrongAction('Someone is judge already')
@@ -80,7 +80,7 @@ class Game:
return self.try_view_black_card(player)
- def try_play_card(self, player, card_id):
+ def try_play_card(self, player: Player, card_id: int) -> str:
if self.state is not GameState.WAITING_COLLECTION:
raise WrongAction('Who asked you to play now ?!')
@@ -105,7 +105,7 @@ class Game:
return success({'card_id': card_id})
- def try_collect_cards(self, player):
+ def try_collect_cards(self, player: Player) -> str:
if self.state is not GameState.WAITING_COLLECTION:
raise WrongAction("Do you think it's the moment for collection !?")
@@ -124,7 +124,7 @@ class Game:
return self.try_view_played_cards(player)
- def try_designate_card(self, player, card_id):
+ def try_designate_card(self, player: Player, card_id: int) -> str:
if self.state is not GameState.WAITING_DESIGNATION:
raise WrongAction('Not now, moron !')
@@ -173,16 +173,16 @@ class Game:
return success(None)
- def try_view_player_cards(self, player):
+ def try_view_player_cards(self, player: Player) -> str:
return success([(idx, desc) for idx, (_, desc) in player.cards.items()])
- def try_view_played_cards(self, player):
+ def try_view_played_cards(self, player: Player):
if self.state is not GameState.WAITING_DESIGNATION:
raise WrongAction('Not now, moron !')
return success([desc for (_, desc), _ in self.board.played_cards])
- def try_view_black_card(self, player):
+ def try_view_black_card(self, player: Player) -> str:
card = self.board.current_black_card
if card is not None:
@@ -190,7 +190,7 @@ class Game:
raise WrongAction('The black card has not been revealed yet')
- def disconnect(self, player):
+ def disconnect(self, player: Player) -> None:
if self.judge is player:
self.judge = None