diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2018-03-09 13:38:22 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2018-03-09 13:38:22 +0100 |
commit | 493b116f73ec3912ca7af3d6ece3434279cbcfb5 (patch) | |
tree | b6955491311fb0d810e9de9a7dd9b8059d04a10c /swiftstory/Player.py | |
parent | 735bc5af0929392f27386aa3fa0c26d39f300672 (diff) |
renamed the project SwiftStory
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/Player.py')
-rw-r--r-- | swiftstory/Player.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/swiftstory/Player.py b/swiftstory/Player.py new file mode 100644 index 0000000..cc64d17 --- /dev/null +++ b/swiftstory/Player.py @@ -0,0 +1,43 @@ +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 get_has_played(self): + return self.has_played + + def set_has_played(self, has=True): + self.has_played = has + + def inc_score(self): + self.score += 1 + self.send_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 send_notification(self, obj): + if self.client is None: + return + + message = json.dumps({'type': 'notification', 'content': obj}) + + self.client.send_notification(message) |