From 741f8234edde84dccefcbf5dc0ba3b70c0e016e2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 29 Dec 2021 19:21:45 +0100 Subject: Add docstrings to all modules Signed-off-by: Olivier Gayot --- swiftstory/game.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'swiftstory/game.py') diff --git a/swiftstory/game.py b/swiftstory/game.py index c46df4b..b2ec493 100644 --- a/swiftstory/game.py +++ b/swiftstory/game.py @@ -1,3 +1,5 @@ +""" Module that defines the main component of the game. """ + from enum import Enum, auto import random from typing import List, Optional, Tuple @@ -9,12 +11,14 @@ from swiftstory.status import error, success class GameState(Enum): + """ Enumeration of the different game states. """ WAITING_NEW_JUDGE = auto(), WAITING_COLLECTION = auto(), WAITING_DESIGNATION = auto(), class Game: + """ Represent a game, including the board, players and state. """ def __init__(self, white_desc: List[str], black_desc: List[str]) -> None: self.state = GameState.WAITING_NEW_JUDGE @@ -31,6 +35,7 @@ class Game: random.shuffle(self.board.black_pick) def try_join(self, player: Player) -> str: + """ Attempt to join the game. Return an answer. """ if len(self.players) >= 10: raise JoinError('too many players in this game') @@ -64,6 +69,7 @@ class Game: def try_become_judge(self, player: Player) -> str: + """ Attempt to become the judge of the game. Return an answer. """ if self.state is not GameState.WAITING_NEW_JUDGE: # TODO what if the judge has quit ? raise WrongAction('Someone is judge already') @@ -81,6 +87,7 @@ class Game: def try_play_card(self, player: Player, card_id: int) -> str: + """ Attempt to play a card. Return an answer. """ if self.state is not GameState.WAITING_COLLECTION: raise WrongAction('Who asked you to play now ?!') @@ -106,6 +113,8 @@ class Game: def try_collect_cards(self, player: Player) -> str: + """ Attempt to collect the cards play in the current round. Return an + answer. """ if self.state is not GameState.WAITING_COLLECTION: raise WrongAction("Do you think it's the moment for collection !?") @@ -125,6 +134,7 @@ class Game: def try_designate_card(self, player: Player, card_id: Optional[int]) -> str: + """ Attempt to designate the best card. Return an answer. """ if self.state is not GameState.WAITING_DESIGNATION: raise WrongAction('Not now, moron !') @@ -177,15 +187,19 @@ class Game: return move_on() def try_view_player_cards(self, player: Player) -> str: + """ Attempt to view the cards of the given player. Return an answer. """ return success([(idx, desc) for idx, (_, desc) in player.cards.items()]) def try_view_played_cards(self, player: Player) -> str: + """ Attempt to view the cards that have been played. Return an answer. + """ 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: Player) -> str: + """ Attempt to view the black card. Return an answer. """ card = self.board.current_black_card if card is not None: @@ -194,6 +208,7 @@ class Game: raise WrongAction('The black card has not been revealed yet') def disconnect(self, player: Player) -> None: + """ Deatch a player from the game. """ if self.judge is player: self.judge = None -- cgit v1.2.3