diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-29 19:21:45 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-29 20:06:14 +0100 |
commit | 741f8234edde84dccefcbf5dc0ba3b70c0e016e2 (patch) | |
tree | c6207bfd9c20eeac59bea2ffef5d4fad70108c29 /swiftstory/player.py | |
parent | f5edd5035d06adc7b6bceb1f521b4911706cde0b (diff) |
Add docstrings to all modules
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/player.py')
-rw-r--r-- | swiftstory/player.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/swiftstory/player.py b/swiftstory/player.py index 7243585..2df6882 100644 --- a/swiftstory/player.py +++ b/swiftstory/player.py @@ -1,9 +1,12 @@ +""" Module defining the player class. """ + import asyncio import json from typing import Any, Dict, Tuple class Player: + """ Represent a player. """ def __init__(self) -> None: self.cards: Dict[int, Tuple[int, str]] = {} self.next_idx = 0 @@ -16,9 +19,11 @@ class Player: self.notifications: asyncio.Queue = asyncio.Queue() def pop_card(self, card_id: int) -> Tuple[int, str]: + """ Take and return the card at index card_id. """ return self.cards.pop(card_id) def inc_score(self) -> None: + """ Increase the score by one. """ self.score += 1 self.register_notification({ 'op': 'updated_score', @@ -26,11 +31,13 @@ class Player: }) def receive_card(self, card: Tuple[int, str]) -> int: + """ Receive a card and return its index. """ self.cards[self.next_idx] = card self.next_idx += 1 return self.next_idx - 1 def register_notification(self, obj: Any) -> None: + """ Register a notification to be picked up by the client. """ message = json.dumps({'type': 'notification', 'content': obj}) self.notifications.put_nowait(message) |