Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomly choose color when player who played +4 or wildcard get skipped #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down
7 changes: 7 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -85,6 +87,17 @@ def turn(self):
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):
Expand Down