diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 15:27:43 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-12-23 23:15:21 +0100 |
commit | 82cd09e010783b81ec58145c7682f4b8da49ac85 (patch) | |
tree | 83b3e61aaa4befcd340a01b2fb147a2306bdb29e /swiftstory/player.py | |
parent | 1be5c49ae402b768f9206724abdd503c18933ae1 (diff) |
Use lowercase module names
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/player.py')
-rw-r--r-- | swiftstory/player.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/swiftstory/player.py b/swiftstory/player.py new file mode 100644 index 0000000..7193b64 --- /dev/null +++ b/swiftstory/player.py @@ -0,0 +1,38 @@ +import json + + +class Player: + def __init__(self, client): + self.cards = {} + self.next_idx = 0 + + self.client = client + + self.score = 0 + + self.has_played = False + + self.name = 'default' + + def pop_card(self, card_id): + return self.cards.pop(card_id) + + def inc_score(self): + self.score += 1 + self.register_notification({ + 'op': 'updated_score', + 'content': self.score, + }) + + def receive_card(self, card): + self.cards[self.next_idx] = card + self.next_idx += 1 + return self.next_idx - 1 + + def register_notification(self, obj): + if self.client is None: + return + + message = json.dumps({'type': 'notification', 'content': obj}) + + self.client.register_notification(message) |