Make game_handler
support starting a game with a range of playeres.
Allow a game to start even if `max_players` is not reached. Adding a new command `play game` to start a game if the number of players is between max and min no. of players. Make tests pass with the new change.
This commit is contained in:
parent
fc1d134685
commit
6df10749fb
|
@ -53,6 +53,8 @@ class TestConnectFourBot(BotTestCase):
|
||||||
`start game`
|
`start game`
|
||||||
* To start a game against another player, type
|
* To start a game against another player, type
|
||||||
`start game with @<player-name>`
|
`start game with @<player-name>`
|
||||||
|
* To play game with the current number of players, type
|
||||||
|
`play game`
|
||||||
* To quit a game at any time, type
|
* To quit a game at any time, type
|
||||||
`quit`
|
`quit`
|
||||||
* To end a game with a draw, type
|
* To end a game with a draw, type
|
||||||
|
|
|
@ -111,6 +111,8 @@ class TestGameHandlerBot(BotTestCase):
|
||||||
`start game with @<player-name>`
|
`start game with @<player-name>`
|
||||||
* To start a game with the computer, type
|
* To start a game with the computer, type
|
||||||
`start game with` @**test-bot**
|
`start game with` @**test-bot**
|
||||||
|
* To play game with the current number of players, type
|
||||||
|
`play game`
|
||||||
* To quit a game at any time, type
|
* To quit a game at any time, type
|
||||||
`quit`
|
`quit`
|
||||||
* To end a game with a draw, type
|
* To end a game with a draw, type
|
||||||
|
|
|
@ -72,6 +72,8 @@ class GameAdapter(object):
|
||||||
`start game`
|
`start game`
|
||||||
* To start a game against another player, type
|
* To start a game against another player, type
|
||||||
`start game with @<player-name>`{}
|
`start game with @<player-name>`{}
|
||||||
|
* To play game with the current number of players, type
|
||||||
|
`play game`
|
||||||
* To quit a game at any time, type
|
* To quit a game at any time, type
|
||||||
`quit`
|
`quit`
|
||||||
* To end a game with a draw, type
|
* To end a game with a draw, type
|
||||||
|
@ -167,6 +169,9 @@ class GameAdapter(object):
|
||||||
elif content.lower().startswith('start game'):
|
elif content.lower().startswith('start game'):
|
||||||
self.command_start_game(message, sender, content)
|
self.command_start_game(message, sender, content)
|
||||||
|
|
||||||
|
elif content.lower().startswith('play game'):
|
||||||
|
self.command_play(message, sender, content)
|
||||||
|
|
||||||
elif content.lower() == 'accept':
|
elif content.lower() == 'accept':
|
||||||
self.command_accept(message, sender, content)
|
self.command_accept(message, sender, content)
|
||||||
|
|
||||||
|
@ -323,6 +328,21 @@ class GameAdapter(object):
|
||||||
return
|
return
|
||||||
self.join_game(game_id, sender, message)
|
self.join_game(game_id, sender, message)
|
||||||
|
|
||||||
|
def command_play(self, message: Dict[str, Any], sender: str, content: str) -> None:
|
||||||
|
game_id = self.get_invite_in_subject(
|
||||||
|
message['subject'], message['display_recipient'])
|
||||||
|
if game_id is '':
|
||||||
|
self.send_reply(
|
||||||
|
message, 'There is not a game in this subject. Type `help` for all commands.')
|
||||||
|
return
|
||||||
|
num_players = len(self.get_players(game_id))
|
||||||
|
if num_players >= self.min_players and num_players <= self.max_players:
|
||||||
|
self.start_game(game_id)
|
||||||
|
else:
|
||||||
|
self.send_reply(
|
||||||
|
message, 'Join {} more players to start the game'.format(self.max_players-num_players)
|
||||||
|
)
|
||||||
|
|
||||||
def command_leaderboard(self, message: Dict[str, Any], sender: str, content: str) -> None:
|
def command_leaderboard(self, message: Dict[str, Any], sender: str, content: str) -> None:
|
||||||
stats = self.get_sorted_player_statistics()
|
stats = self.get_sorted_player_statistics()
|
||||||
num = 5 if len(stats) > 5 else len(stats)
|
num = 5 if len(stats) > 5 else len(stats)
|
||||||
|
|
Loading…
Reference in a new issue