This commit is contained in:
eaocto 2019-10-13 21:33:48 +00:00 committed by GitHub
commit 564aef4425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View file

@ -38,8 +38,11 @@ def do_skip(bot, player, job_queue=None):
if (skipped_player.waiting_time < 0):
skipped_player.waiting_time = 0
# 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
@ -54,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)

7
bot.py
View file

@ -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(

13
game.py
View file

@ -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):