Ejemplo n.º 1
0
 def join(self, member):
     if self.status != Status.JOINABLE:
         raise NotAllowedCommand(_('error_joinable'))
     if self.get_team_member(member) is None:
         self.auto_join(member)
     else:
         raise NotAllowedCommand(_('error_already_joined', team=self.get_team_member(member).name))
Ejemplo n.º 2
0
    def show(self, member, word):
        if self.status == Status.PLAY:
            if member.id in self.current_turn.members.keys():
                found, color = self.grid_table.show(word)
                if not found:
                    raise NotAllowedCommand(_('error_word_not_found', word=word))
                elif color == ColorGame.ASSASSIN:
                    self.status = Status.STOPPED
                    self.winner = self.next_turn

                    return ActionResult.FINISH
                elif self.verify_victory_condition() is None:
                    if color != self.current_turn.color:
                        self.current_turn, self.next_turn = self.next_turn, self.current_turn
                        return ActionResult.NOT_GUESS
                    else:
                        return ActionResult.GUESS
                else:
                    self.winner = self.verify_victory_condition()
                    self.status = Status.STOPPED
                    return ActionResult.FINISH
            else:
                raise NotAllowedCommand(_('error_team_not_allowed', team=self.current_turn.name))
        else:
            raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 3
0
 def pass_turn(self, member):
     if self.status == Status.PLAY:
         if member.id in self.current_turn.members.keys():
             self.current_turn, self.next_turn = self.next_turn, self.current_turn
         else:
             raise NotAllowedCommand(_('error_team_not_allowed', team=self.current_turn.name))
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 4
0
 def leave(self, member):
     if self.status != Status.JOINABLE:
         raise NotAllowedCommand(_('error_joinable'))
     team = self.get_team_member(member)
     if team is not None:
         team.leave(member)
     else:
         raise NotAllowedCommand(_('error_not_join'))
Ejemplo n.º 5
0
 def change_team(self, member):
     if self.status != Status.JOINABLE:
         raise NotAllowedCommand(_('error_joinable'))
     if member.id in self.team_red.members.keys():
         self.team_red.leave(member)
         self.team_blue.join(member)
     elif member.id in self.team_blue.members.keys():
         self.team_blue.leave(member)
         self.team_red.join(member)
     else:
         raise NotAllowedCommand(_('error_not_join'))
Ejemplo n.º 6
0
 def play(self, tag):
     if self.status != Status.JOINABLE:
         raise NotAllowedCommand(_('error_joinable'))
     elif not self.has_masters():
         raise NotAllowedCommand(_('error_need_two_master'))
     else:
         self.status = Status.PLAY
         self.grid_table = WordTable()
         self.grid_table.generate_words(tag)
         self.current_turn = self.team_red
         self.next_turn = self.team_blue
Ejemplo n.º 7
0
 def join_team_as_master(self, member):
     if self.team_red.master is not None and self.team_blue.master is not None:
         raise NotAllowedCommand(_('error_master_already_set'))
     if self.team_red.master is None and member.id not in self.team_blue.members.keys():
         self.team_red.set_master(member)
         return self.team_red.name
     elif self.team_blue.master is None and member.id not in self.team_red.members.keys():
         self.team_blue.set_master(member)
         return self.team_blue.name
     else:
         raise NotAllowedCommand(_('error_master_other_team'))
Ejemplo n.º 8
0
 def start(self):
     if self.status == Status.JOINABLE:
         raise NotAllowedCommand(_('error_started'))
     else:
         self.status = Status.JOINABLE
         self.team_red = Team(ColorGame.RED, 'Red')
         self.team_blue = Team(ColorGame.BLUE, 'Blue')
Ejemplo n.º 9
0
 def add_tag(self, tag, lang):
     if self.get_tag_id(tag) is None:
         self.__connect__()
         sql = "INSERT INTO `tags` (`id`, `tagname`, `lang`, `modifiable`) VALUES (NULL, %s, %s, '1')"
         value = [tag, lang]
         self.cursor.execute(sql, value)
         self.__commit__()
         self.__disconnect__()
     else:
         raise NotAllowedCommand("tag already present")
Ejemplo n.º 10
0
    async def addword(self, ctx, tag, *, member: discord.Member = None):

        if not isinstance(ctx.message.channel, discord.DMChannel):
            await ctx.send(_('error_addword_private'))
        else:
            try:
                member = member or ctx.author
                if self.db.get_tag_id(tag) is not None:
                    self.user_tag[member.id] = tag
                    await ctx.send(_('tag_adding', tag=tag))
                else:
                    raise NotAllowedCommand(_('error_tag_not_exists', tag=tag))
            except NotAllowedCommand as err:
                await ctx.send(err.message)
Ejemplo n.º 11
0
    def join_as_master(self, member):
        """Joins the member to one team if available

           Args:
               member: A member instance

           Returns:
               A string with the name of the team

           Raises:
               NotAllowedCommand: An error occured when there are not spaces to be master available
           """
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        else:
            return self.join_team_as_master(member)
Ejemplo n.º 12
0
 def pass_turn(self, guild, channel, member):
     if (guild.id, channel.id) in self.game_helper.matches.keys():
         return self.game_helper.matches[(guild.id,
                                          channel.id)].pass_turn(member)
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 13
0
 def show_word(self, guild, channel, member, word):
     if (guild.id, channel.id) in self.game_helper.matches.keys():
         return self.game_helper.matches[(guild.id,
                                          channel.id)].show(member, word)
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 14
0
    def generate_words(self, tag):
        """Generate the word from the database

            """
        db = Database()
        listOfWord = db.get_words_by_tag(tag)
        if len(listOfWord) < self.size:
            raise NotAllowedCommand(_('error_missing_words', tag=tag))
        self.words_str = random.sample(listOfWord, self.size)
        self.red_words = random.sample(self.words_str, self.number_red)

        red_set = set(self.red_words)
        self.blue_words = random.sample(
            [x for x in self.words_str if x not in red_set], self.number_blue)

        blue_set = set(self.blue_words)
        self.assassin_words = random.sample([
            x for x in self.words_str if x not in red_set and x not in blue_set
        ], self.number_assassin)
        self.white_words = [
            x for x in self.words_str if x not in red_set and x not in blue_set
            and x not in self.assassin_words
        ]

        try:
            self.red_revealed_path = random.sample([
                f for f in glob.glob(self.images_res_path +
                                     "/red_revealed/*.png")
            ], self.number_red)
        except ValueError:
            self.red_revealed_path = glob.glob(self.images_res_path +
                                               "/red_revealed/*.png")
        try:
            self.blue_revealed_path = random.sample([
                f for f in glob.glob(self.images_res_path +
                                     "/blue_revealed/*.png")
            ], self.number_blue)
        except ValueError:
            self.blue_revealed_path = glob.glob(self.images_res_path +
                                                "/blue_revealed/*.png")
        try:
            self.assassin_revealed_path = random.sample([
                f for f in glob.glob(self.images_res_path +
                                     "/black_revealed/*.png")
            ], self.number_assassin)
        except ValueError:
            self.assassin_revealed_path = glob.glob(self.images_res_path +
                                                    "/assassin_revealed/*.png")
        try:
            self.white_revealed_path = random.sample([
                f for f in glob.glob(self.images_res_path +
                                     "/white_revealed/*.png")
            ], self.number_white)
        except ValueError:
            self.white_revealed_path = glob.glob(self.images_res_path +
                                                 "/white_revealed/*.png")

        self.revealed_counter = {
            'red': 0,
            'blue': 0,
            'white': 0,
            'assassin': 0
        }

        self.create_grid()
Ejemplo n.º 15
0
 def leave(self, guild_id, channel_id, member):
     if (guild_id, channel_id) in self.matches.keys():
         self.matches[(guild_id, channel_id)].leave(member)
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 16
0
 def play(self, guild_id, channel_id, tag):
     if (guild_id, channel_id) in self.matches.keys():
         self.matches[(guild_id, channel_id)].play(tag)
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 17
0
 def stop(self, guild_id, channel_id):
     if (guild_id, channel_id) in self.matches.keys():
         self.matches[(guild_id, channel_id)].stop()
     else:
         raise NotAllowedCommand(_('error_not_started'))
Ejemplo n.º 18
0
 def stop(self):
     if self.status == Status.NOT_STARTED or self.status == Status.STOPPED:
         raise NotAllowedCommand(_('error_not_started'))
     else:
         self.status = Status.STOPPED
Ejemplo n.º 19
0
 def show(self):
     if self.revealed:
         raise NotAllowedCommand(_('error_word_show'))
     else:
         self.revealed = True