Fixed; skipped player will not draw card if currently on "choosing color" step, +4 will be correctly given to the next player.

Game will also randomly choose color if player leave without choosing color after playing wildcard or +4.
This commit is contained in:
eaocto 2018-12-13 16:34:22 +07:00
parent 8c6a55685d
commit 36530a9e65
3 changed files with 32 additions and 6 deletions

View file

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

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