async def check_blackjack(self, player): player.card_value = player.calculate_card_value() me = self.bot.get_user(player.user_id) if player.card_value > 21: embed = black_jack_embed(me, player, outcome="lose") embed.title = "Busted!" await player.message.edit(embed=embed) await self.remove(player) if player.card_value == 21: embed = black_jack_embed(me, player, outcome="win") embed.title = "Blackjack!" await player.message.edit(embed=embed) await self.remove(player)
async def init_blackjack(self, ctx, bet_amount): if ctx.channel.id in self.live_games: game = self.live_games[ctx.channel.id] else: game = Game(ctx.channel.id) self.live_games[ctx.channel.id] = game if not len(game.participants) == blackjack_player_limit: player = Player(ctx.author.id, bet_amount, game) if ctx.author.id not in game.participants: game.participants[ctx.author.id] = player game.deck.give_random_card(player, 2) embed = black_jack_embed(ctx.author, player) msg = await ctx.channel.send(embed=embed) player.message = msg self.reactable_messages[msg.id] = player emotes = [hit_emoji_id, stay_emoji_id, double_emoji_id] for emote in emotes: reaction = self.bot.get_emoji(emote) await msg.add_reaction(reaction) await self.check_blackjack(player) else: await ctx.channel.send(embed=simple_embed( "You've already joined the game. You can try joining another lobby.", "", discord.Color.red())) else: await ctx.channel.send(embed=simple_embed( "The lobby if full. Try in another channel.", "", discord.Color.red()))
async def evaluate_results(self, game): participants = game.participants dealer_card_value = game.calculate_card_value() for participant in list(participants): player = participants[participant] me = self.bot.get_user(player.user_id) if dealer_card_value > 21 or dealer_card_value < player.card_value: await player.message.edit(embed=black_jack_embed( me, player, outcome="win", hidden=False)) elif dealer_card_value > player.card_value: await player.message.edit(embed=black_jack_embed( me, player, outcome="lose", hidden=False)) else: await player.message.edit(embed=black_jack_embed( me, player, outcome="tie", hidden=False)) await self.remove(player) del self.live_games[game.channel]
async def check_active_session(self, player): participants = player.game.participants for person in participants: if participants[person].stay: me = self.bot.get_user(player.user_id) embed = black_jack_embed(me, player) embed.description = "**Status: **Waiting for other players..." await player.message.edit(embed=embed) return await self.dealers_play(player.game)
async def hit(self, player): player.game.deck.give_random_card(player, 1) me = self.bot.get_user(player.user_id) await player.message.edit(embed=black_jack_embed(me, player)) await self.check_blackjack(player) await self.check_active_session(player.game)