def do_play_card(bot, chat_id, game, player, result_id, user): global ranking game.ranking = init_ranking(chat_id) card = c.from_str(result_id) game.play_card(card) player.cards.remove(card) if len(player.cards) == 1: player.uno = True player.unoDrawn = False #send_async(bot, chat_id, text="UNO!") elif len(player.cards) == 0: if(game.playerWhichIsBluffing != None and game.playerWhichIsBluffing.user.id is player.user.id): game.playerWhichIsBluffing = None wins = add_win(chat_id,user) send_async(bot, chat_id, text="%s ganhou, esse prodígio!\nTotal de vitórias: %d (%d essa semana)" % (display_name(user,game),wins[0],wins[1])) if(game.choosing_color): game.choosing_color = False result_id = choice(c.COLORS) game.choose_color(result_id) send_async(bot, chat_id, text="Nova cor: %s" % display_color(result_id)) if len(game.players) < 3: send_async(bot, chat_id, text="Fim de jogo!") gm.end_game(chat_id, user) else: gm.leave_game(user, chat_id) if game.choosing_color: send_async(bot, chat_id, text="Escolha uma cor!") if botan: botan.track(Message(randint(1, 1000000000), user, datetime.now(), Chat(chat_id, 'group')), 'Cartas jogadas')
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user last = player.game.last_card us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: if len(player.cards) >= 1: send_async(bot, chat.id, text=_("Please choose a color")) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} won!", multi=game.translate).format(name=user.first_name)) if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 game.players_won_list.append(player.prev.user.id) try: if last.special == c.CHOOSE or last.special == c.DRAW_FOUR: game.last_card.color = random.choice(c.COLORS) send_async(bot, chat.id, text=__( "Color randomly choosen to: {col}", multi=game.translate).format( col=c.COLOR_ICONS[game.last_card.color])) gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: us2.games_played += 1 us2.last_places += 1 gm.end_game(chat, user)
def do_play_card(bot, chat_id, game, player, result_id, user): card = c.from_str(result_id) game.play_card(card) player.cards.remove(card) if len(player.cards) == 1: player.uno = True #send_async(bot, chat_id, text="UNO!") if len(player.cards) == 0: if(game.playerWhichIsBluffing != None and game.playerWhichIsBluffing.user.id is player.user.id): game.playerWhichIsBluffing = None send_async(bot, chat_id, text="%s ganhou, esse prodígio!" % display_name(user)) if(game.choosing_color): game.choosing_color = False result_id = choice(c.COLORS) game.choose_color(result_id) send_async(bot, chat_id, text="Nova cor: %s" % display_color(result_id)) if len(game.players) < 3: send_async(bot, chat_id, text="Fim de jogo!") gm.end_game(chat_id, user) else: gm.leave_game(user, chat_id) if game.choosing_color: send_async(bot, chat_id, text="Escolha uma cor!") if botan: botan.track(Message(randint(1, 1000000000), user, datetime.now(), Chat(chat_id, 'group')), 'Cartas jogadas')
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=__("Please choose a color", multi=game.translate)) if len(player.cards) == 15: send_async(bot, chat.id, text="Amazon khulgya, wew") if len(player.cards) == 13: send_async(bot, chat.id, text="AliExpress khulgya, wew") if len(player.cards) == 11: send_async(bot, chat.id, text="Mall khulgya, wew") if len(player.cards) == 9: send_async(bot, chat.id, text="Dukaan khulgya, wew") if len(player.cards) == 7: send_async(bot, chat.id, text="Dukaan soonTM") if len(player.cards) == 1: send_async(bot, chat.id, text="UNO | Is chutiye ka ek hi card bach gaya, maro!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} jeet gaya bc!", multi=game.translate) .format(name=user.first_name)) if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 try: gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: us2.games_played += 1 gm.end_game(chat, user)
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=__("Please choose a color", multi=game.translate)) if game.current_player.user.id == bot.id: print('escolheu') color = c.COLORS[random.randint(0, 3)] game.choose_color(color) send_async(bot, chat.id, text=display_color_group(color, game)) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} won!", multi=game.translate).format(name=user.first_name)) if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 try: gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: us2.games_played += 1 gm.end_game(chat, user)
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=_("Please choose a color")) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} won!", multi=game.translate).format(name=user.first_name)) send_async(bot, chat.id, text=__("Game ended! Flawless Victory!")) if us.stats: # us.games_played += 1 if game.players_won is 0: us.first_places += 1 if game.mode == 'one': gm.end_game(chat, user) else: game.players_won += 1 try: if game.mode != 'one': gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: # us2.games_played += 1 us2.last_places += 1 gm.end_game(chat, user)
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=_("Please choose a color")) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} won!", multi=game.translate).format(name=user.first_name)) if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 try: gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: us2.games_played += 1 gm.end_game(chat, user) if botan: random_int = random.randrange(1, 999999999) botan.track( Message(random_int, user, datetime.now(), Chat(chat.id, 'group')), 'Played cards')
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=_("Please choose a color")) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: send_async(bot, chat.id, text=__("{name} won!", multi=game.translate) .format(name=user.first_name)) if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 try: gm.leave_game(user, chat) except NotEnoughPlayersError: send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) us2 = UserSetting.get(id=game.current_player.user.id) if us2 and us2.stats: us2.games_played += 1 gm.end_game(chat, user) if botan: botan.track(Message(randint(1, 1000000000), user, datetime.now(), Chat(chat.id, 'group')), 'Played cards')
def do_play_card(bot, player, result_id): """Plays the selected card and sends an update to the group if needed""" card = c.from_str(result_id) player.play(card) game = player.game chat = game.chat user = player.user us = UserSetting.get(id=user.id) if not us: us = UserSetting(id=user.id) if us.stats: us.cards_played += 1 if game.choosing_color: send_async(bot, chat.id, text=_("Please choose a color")) if len(player.cards) == 1: send_async(bot, chat.id, text="UNO!") if len(player.cards) == 0: if game.mode != 'score': send_async( bot, chat.id, text=__("{name} won!", multi=game.translate).format(name=user.first_name)) if game.mode == "score": game.add_score(player) score = sum([n[0] for n in game.last_round_score]) bot.sendMessage( chat.id, text=__("Added {pt} point", "Added {pt} points", score).format(pt=score) + "\n" + ("Points to win: {score}").format(score=game.win_score) + "\n\n" + ("Current standings:\n") + "\n".join([ "{no}. {name}: {pt}".format( no=i + 1, name=x[0].user.first_name, pt=x[1]) for i, x in enumerate( sorted(game.get_scores(), key=lambda x: x[1], reverse=True)) ]) + "\n\nCard Opponents Players:\n" + " | ".join([ "{cl} {vl} (+{pt})".format( cl=c.COLOR_ICONS[n[1].color or 'x'], vl=n[1].value or n[1].special, pt=n[0]).replace('draw_four', '+4').replace( 'draw', '+2').replace('colorchooser', 'Color Chooser').replace( 'skip', 'Skip').replace( 'reverse', 'Reverse') for n in sorted(game.last_round_score, key=lambda x: x[0]) ])) players_cache = game.players highest = sorted(zip(players_cache, map(game.get_score, players_cache)), key=lambda x: x[1])[-1] if highest[1] >= game.win_score: if game.mode == 'score': send_async(bot, chat.id, text=__("Game ended! {name} won the game!", multi=game.translate).format( name=highest[0].user.first_name)) if us.stats: us.first_places += 1 for player in players_cache: us_ = UserSetting.get(id=player.user.id) if not us: us_ = UserSetting(id=player.user.id) us_.games_played += 1 gm.end_game(chat, user) else: sleep(5) game.reset_cards() game.new_round() bot.sendSticker(chat.id, sticker=c.STICKERS[str(game.last_card)], timeout=TIMEOUT) return # If game mode is "score", 'do_play_card' should stop here if us.stats: us.games_played += 1 if game.players_won is 0: us.first_places += 1 game.players_won += 1 if game.mode != "score": send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) gm.end_game(chat, user)