diff --git a/actions.py b/actions.py index 6b03236..ca9e166 100644 --- a/actions.py +++ b/actions.py @@ -38,13 +38,11 @@ def do_skip(bot, player, job_queue=None): if (skipped_player.waiting_time < 0): skipped_player.waiting_time = 0 - # if player get skipped after playing wildcard or +4 - # before getting to choose color, then choose color randomly - if game.choosing_color: - game.last_card.color = random.choice(c.COLORS) - + # skip drawing if current player should choose color + # which means current player has played a card try: - skipped_player.draw() + if not game.choosing_color: + skipped_player.draw() except DeckEmptyError: pass @@ -59,6 +57,14 @@ def do_skip(bot, player, job_queue=None): logger.info("{player} was skipped!. " .format(player=display_name(player.user))) game.turn() + + # send message to indicate the game has randomly choosen the color + if game._randomed_color: + send_async(bot, chat.id, + text=__("Color randomly choosen to: {col}", + multi=game.translate).format( + col=c.COLOR_ICONS[game.last_card.color])) + if job_queue: start_player_countdown(bot, game, job_queue) diff --git a/bot.py b/bot.py index cdd2ae4..502a86d 100644 --- a/bot.py +++ b/bot.py @@ -200,6 +200,13 @@ def leave_game(bot, update): else: if game.started: + # send message to indicate the game has randomly choosen the color + if game._randomed_color: + send_async(bot, chat.id, + text=__("Color randomly choosen to: {col}", + multi=game.translate).format( + col=c.COLOR_ICONS[game.last_card.color]), + reply_to_message_id=update.message.message_id) send_async(bot, chat.id, text=__("Okay. Next Player: {name}", multi=game.translate).format( diff --git a/game.py b/game.py index 3234f9b..6766c44 100644 --- a/game.py +++ b/game.py @@ -21,6 +21,7 @@ import logging from config import ADMIN_LIST, OPEN_LOBBY, DEFAULT_GAMEMODE, ENABLE_TRANSLATIONS from datetime import datetime +import random from deck import Deck import card as c @@ -30,6 +31,7 @@ class Game(object): current_player = None reversed = False choosing_color = False + _randomed_color = False started = False draw_counter = 0 players_won = 0 @@ -85,6 +87,17 @@ class Game(object): self.current_player = self.current_player.next self.current_player.drew = False self.current_player.turn_started = datetime.now() + self._reset_choosing_color() + + def _reset_choosing_color(self): + """Reset 'choosing_color' flag to false and randomly choose color + if it hasn't been done, eg. when player is skipped or leave after + playing wildcard or +4 card.""" + if self.choosing_color and not self.last_card.color: + self.last_card.color = random.choice(c.COLORS) + self._randomed_color = True + else: + self._randomed_color = False self.choosing_color = False def _first_card_(self):