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

Max 10 players + DeckEmptyError bug fix #68

Open
wants to merge 7 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
11 changes: 10 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
"time_removal_after_skip": 20,
"min_fast_turn_time": 15,
"min_players": 2
"max_players": 10
}
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
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)
4 changes: 4 additions & 0 deletions errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ class NotEnoughPlayersError(Exception):

class DeckEmptyError(Exception):
pass


class MaxPlayersError(Exception):
pass
5 changes: 4 additions & 1 deletion game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from game import Game
from player import Player
from errors import (AlreadyJoinedError, LobbyClosedError, NoGameInChatError,
NotEnoughPlayersError)
NotEnoughPlayersError, MaxPlayersError)


class GameManager(object):
Expand Down Expand Up @@ -69,6 +69,9 @@ def join_game(self, user, chat):
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()

Expand Down
3 changes: 1 addition & 2 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def draw_first_hand(self):
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

Expand Down