diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-11-01 23:28:07 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-11-01 23:47:25 +0100 |
commit | 0fca30bbdac79d8d33e152e7e7116c5ffa1356ca (patch) | |
tree | bfcd33f2bd68f220ffad956b07d37002dc06de9f /swiftstory/Game.py | |
parent | d66b6d0115e620f8c12629a5822cf31d3e976a20 (diff) |
Add WrongAction exception and use it instaed of returning error
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/Game.py')
-rw-r--r-- | swiftstory/Game.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/swiftstory/Game.py b/swiftstory/Game.py index cb02a1d..0df2e16 100644 --- a/swiftstory/Game.py +++ b/swiftstory/Game.py @@ -1,5 +1,6 @@ import random +from swiftstory.exception import WrongAction from swiftstory.Player import Player from swiftstory.Board import Board from swiftstory.Status import error, success @@ -68,7 +69,7 @@ class Game: def try_become_judge(self, player): if self.state is not self.WAITING_NEW_JUDGE: # TODO what if the judge has quit ? - return error('Someone is judge already') + raise WrongAction('Someone is judge already') self.judge = player self.board.reveal_next_black_card() @@ -84,17 +85,17 @@ class Game: def try_play_card(self, player, card_id): if self.state is not self.WAITING_COLLECTION: - return error('Who asked you to play now ?!') + raise WrongAction('Who asked you to play now ?!') if self.judge is player: - return error('You\'re the judge, you silly') + raise WrongAction('You\'re the judge, you silly') elif player.has_played: - return error('You already played, you dumb ass') + raise WrongAction('You already played, you dumb ass') try: card = player.pop_card(card_id) except IndexError: - return error('Invalid card id') + raise WrongAction('Invalid card id') player.has_played = True @@ -107,10 +108,10 @@ class Game: def try_collect_cards(self, player): if self.state is not self.WAITING_COLLECTION: - return error('Do you think it\'s the moment for colletion !?') + raise WrongAction('Do you think it\'s the moment for colletion !?') if self.judge is not player: - return error('You\'re not the judge, you fool!') + raise WrongAction('You\'re not the judge, you fool!') self.board.shuffle_played_cards() @@ -126,13 +127,13 @@ class Game: def try_designate_card(self, player, card_id): if self.state is not self.WAITING_DESIGNATION: - return error('Not now, moron !') + raise WrongAction('Not now, moron !') if self.judge is not player: - return error('Who do you think you are !?') + raise WrongAction('Who do you think you are !?') if card_id is None and len(self.board.played_cards) > 0: - return error('There are cards on the board, pick one !') + raise WrongAction('There are cards on the board, pick one !') if card_id is not None or len(self.board.played_cards) > 0: # if there are cards on the board @@ -178,7 +179,7 @@ class Game: def try_view_played_cards(self, player): if self.state is not self.WAITING_DESIGNATION: - return error('Not now, moron !') + raise WrongAction('Not now, moron !') return success([desc for (_, desc), _ in self.board.played_cards]) @@ -188,7 +189,7 @@ class Game: if card is not None: return success(card[1]) - return error('The black card has not been revealed yet') + raise WrongAction('The black card has not been revealed yet') def disconnect(self, player): player.client = None |