Ejemplo n.º 1
0
 async def start(self, ctx, *players: commands.MemberConverter):
     channel = self.get_channel(ctx)
     if channel in self.games:
         await ctx.send(
             f"A game is already happening in here. The players are {[player.display_name for player in self.games[channel].players]}"
         )
     players = [player for player in players]
     if not ctx.author in players:
         players.append(ctx.author)
     self.games[channel] = YahtzeeGame(players)
     await ctx.send(
         f"Game started with {[player.name for player in players]}")
Ejemplo n.º 2
0
    async def start(self, ctx, *players: commands.MemberConverter):
        if not str(ctx.channel.id) in self.channels:
            return (await ctx.send(
                f"This is not a prime number game channel. You need to register it with \"{ctx.prefix}prime register\""
            ))
        players = [i for i in players]
        if not ctx.author in players:
            players.append(ctx.author)
        random.shuffle(players)
        if len(players) < 2:
            await ctx.send("Not enough players")
            return
        playing = True
        playernum = 0
        already_had = []
        while playing:
            lost = False
            player = players[playernum]
            await ctx.send(
                f"{player.mention} It's your turn!\nSend a prime number under 1000000 within 5 seconds or you lose!"
            )

            def check(m):
                return (m.author.id == player.id
                        and m.channel.id == ctx.channel.id
                        and m.content.isdigit())

            try:
                msg = await self.bot.wait_for("message",
                                              check=check,
                                              timeout=5)
                if int(msg.content) >= 1000000:
                    await ctx.send(
                        f"Sorry {msg.author.mention} That number is too big so you are now out of the game"
                    )
                    lost = True
                elif not await self.is_prime(int(msg.content)):
                    await ctx.send(
                        f"Sorry {player.mention}, The number {msg.content} is not prime so you are now out of the game"
                    )
                    lost = True
                elif int(msg.content) in already_had:
                    await ctx.send(
                        f"Sorry {player.mention}, The number {msg.content} has already been used so you are now out of the game"
                    )
                    lost = True
            except asyncio.TimeoutError:
                await ctx.send(
                    f"Sorry {player.mention}, You took too long and are now out of the game"
                )
                lost = True
            if lost:
                next_player = players[(playernum + 1) % len(players)]
                players.remove(player)
                playernum = players.index(next_player) - 1
                if len(players) == 1:
                    await ctx.send(f"{next_player.mention} Wins! Well done!")
                    lokkoin = self.bot.get_cog("lokkoin")
                    if lokkoin:
                        await lokkoin.add_coins(str(next_player.id),
                                                self.reward)
                        await ctx.send(
                            f"Well done {next_player.display_name}, you won {self.reward} lokkoins!"
                        )
                    playing = False
            else:
                already_had.append(int(msg.content))
            playernum += 1
            playernum %= len(players)