This commit is contained in:
DO97 2019-11-03 19:11:47 +07:00 committed by GitHub
commit 2f5516b6b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 4 deletions

11
bot.py
View file

@ -32,7 +32,7 @@ import simple_commands
from actions import do_skip, do_play_card, do_draw, do_call_bluff, start_player_countdown
from config import WAITING_TIME, DEFAULT_GAMEMODE, MIN_PLAYERS
from errors import (NoGameInChatError, LobbyClosedError, AlreadyJoinedError,
NotEnoughPlayersError, DeckEmptyError)
NotEnoughPlayersError, DeckEmptyError, MaxPlayersError)
from internationalization import _, __, user_locale, game_locales
from results import (add_call_bluff, add_choose_color, add_draw, add_gameinfo,
add_no_game, add_not_started, add_other_cards, add_pass,
@ -163,6 +163,11 @@ def join_game(bot, update):
"new players to join."),
reply_to_message_id=update.message.message_id)
except MaxPlayersError:
send_async(bot, chat.id,
text=_("You can't join the game due to the maximum players limit"),
reply_to_message_id=update.message.message_id)
else:
send_async(bot, chat.id,
text=_("Joined the game"),
@ -369,6 +374,10 @@ def start_game(bot, update, args, job_queue):
text=__("At least {minplayers} players must /join the game "
"before you can start it").format(minplayers=MIN_PLAYERS))
elif len(game.players) > MAX_PLAYERS:
send_async(bot, chat.id,
text=__("No more than {maxplayers} players can join the game").format(maxplayers=MAX_PLAYERS))
else:
# Starting a game
game.start()

View file

@ -9,4 +9,5 @@
"time_removal_after_skip": 20,
"min_fast_turn_time": 15,
"min_players": 2
"max_players": 10
}

View file

@ -33,3 +33,4 @@ WAITING_TIME = config.get("waiting_time", 120)
TIME_REMOVAL_AFTER_SKIP = config.get("time_removal_after_skip", 20)
MIN_FAST_TURN_TIME = config.get("min_fast_turn_time", 15)
MIN_PLAYERS = config.get("min_players", 2)
MAX_PLAYERS = config.get("max_players", 10)

View file

@ -36,3 +36,7 @@ class NotEnoughPlayersError(Exception):
class DeckEmptyError(Exception):
pass
class MaxPlayersError(Exception):
pass

View file

@ -23,7 +23,7 @@ import logging
from game import Game
from player import Player
from errors import (AlreadyJoinedError, LobbyClosedError, NoGameInChatError,
NotEnoughPlayersError)
NotEnoughPlayersError, MaxPlayersError)
class GameManager(object):
@ -69,6 +69,9 @@ class GameManager(object):
if not game.open:
raise LobbyClosedError()
if game.started and len(game.players) == 10:
raise MaxPlayersError()
if user.id not in self.userid_players:
self.userid_players[user.id] = list()

View file

@ -62,8 +62,7 @@ class Player(object):
for _ in range(7):
self.cards.append(self.game.deck.draw())
except DeckEmptyError:
for card in self.cards:
self.game.deck.dismiss(card)
self.leave()
raise