예제 #1
0
    async def creategame(self, ctx: CustomContext):
        """
        Creates a game of mafia in this channel.
        To join an existing game, use the `join` command.
        Hosts may delete running games using the `delete` command.
        """
        if ctx.channel.id in self.bot.games:
            return await ctx.send('A game of mafia is already running '
                                  'in this channel.')

        # prevent the user from joining if they are already in a different game
        other_games = list(
            filter(lambda game: ctx.author in game.players,
                   self.bot.games.values()))
        if len(other_games) > 0:
            other_game = other_games[0]
            return await ctx.send(
                'You are already playing another game in the channel {} ({})'.
                format(other_game.channel.mention,
                       other_game.channel.guild.name))

        new_game = Game.create(ctx, self.bot)
        self.bot.games[ctx.channel.id] = new_game
        return await ctx.send('Started a game of mafia in '
                              f'{ctx.message.channel.mention}, '
                              f'hosted by **{ctx.message.author}**')
예제 #2
0
 async def creategame(self, ctx: CustomContext):
     """
     Creates a game of mafia in this server.
     To join an existing game, use the `join` command.
     Hosts may delete running games using the `delete` command.
     """
     if ctx.guild.id in self.bot.games:
         return await ctx.send('A game of mafia is already running '
                               'in this server.')
     new_game = Game.create(ctx, self.bot)
     self.bot.games[ctx.guild.id] = new_game
     return await ctx.send('Started a game of mafia in '
                           f'{ctx.message.channel.mention}, '
                           f'hosted by **{ctx.message.author}**')
예제 #3
0
class CheckEndgameTestCase(unittest.TestCase):
    def setUp(self):
        self.game = Game(Mock(), Mock())

    def test_mafia_and_town_only(self):
        players = []
        town_fac_mock = MockFaction(spec=["name", "has_won"])
        town_fac_mock.name = 'Town'
        mafia_fac_mock = MockFaction(spec=["name", "has_won"])
        mafia_fac_mock.name = 'Mafia'

        # Generate 10 players, half mafia, half town
        for i in range(1, 11):
            if i > 5:
                display_role = 'Town'
                faction = mafia_fac_mock
            else:
                display_role = 'Mafia'
                faction = town_fac_mock
            player = Mock()
            player.user.name = ''.join(['Player', str(i)])
            player.display_role = display_role
            player.faction = faction
            players.append(player)

        self.game.players = players

        test_values = (((True, False), (True, 'Town', [])),
                       ((False, True), (True, 'Mafia', [])),
                       ((False, False), (False, None, None)))

        for win_fac_set, expected_rv in test_values:
            with self.subTest(win_fac_set=win_fac_set,
                              expected_rv=expected_rv):
                town_fac_mock.has_won.return_value = win_fac_set[0]
                mafia_fac_mock.has_won.return_value = win_fac_set[1]
                self.assertEqual(self.game.check_endgame(), expected_rv)
예제 #4
0
 def setUpClass(cls):
     cls.game = Game(Mock(), Mock())
예제 #5
0
 def setUp(self):
     self.game = Game(Mock(), Mock())