예제 #1
0
    def check_valid_skill_dice(input_dice):
        """
        Checks whether the string passed to this method is a valid dice type
        :param input_dice: string
        :return: returns None if successful
        """
        dice_str_data = Character.obtain_dice_data(input_dice)

        # This will check the number of dice:

        if len(dice_str_data[0]) == 0:
            raise InputException("You have not entered the number of dice for"
                                 " a skill. Please try again")

        # This will check the type of dice:

        if len(dice_str_data[1]) == 0:
            raise InputException("You have not entered a valid dice type for a"
                                 " skill. Please try again")

        # Checking whether a valid dice type has been entered by the user:
        for edice in EDice:
            if dice_str_data[1] == edice.name:
                return
        raise InputException("Invalid dice type entry. Please try again")
예제 #2
0
    def edit_skills_last(self, result, character):
        """
        Written by MH
        This function is the final method which checks whether a
        character's skills can be modified
        :param result: a list containing the user's input
        :param character: the instance of character
        :return:
        """
        input_v = InputView()

        try:
            input_v.check_valid_skill_dice(result[1])
            input_v.check_valid_skill_dice(result[2])
            input_v.check_valid_skill_dice(result[3])
            input_v.check_valid_skill_dice(result[4])
            input_v.check_valid_skill_dice(result[5])
            input_v.check_valid_skill_dice(result[6])

            # Start with the first skill input data, not the name:
            # remove the character name from the results list
            # The result list will now be length 6
            del result[0]

            # Get the skills data from each of the args
            num_dice_list = []
            type_dice_list = []

            for i in range(len(result)):
                dice_str_data = \
                    Character.obtain_dice_data(result[i])
                # print("number_dice_str: "+ number_dice_str)
                # print("type_dice_str: " + type_dice_str)
                num_dice_list.append(dice_str_data[0])
                type_dice_list.append(dice_str_data[1])

            try:
                character.check_number_dice(character, num_dice_list)

                try:
                    character.check_type_dice(character, type_dice_list)

                    # If the previous tests pass then the original skills
                    # can be removed and replaced with the updated skills:

                    skills_result = Character.obtain_dice_data(
                        result[0])
                    character.set_brawl(Skill(ESkill.brawl,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[1])
                    character.set_shoot(Skill(ESkill.shoot,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[2])
                    character.set_dodge(Skill(ESkill.dodge,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[3])
                    character.set_might(Skill(ESkill.might,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[4])
                    character.set_finesse(Skill(ESkill.finesse,
                                                character.find_edice
                                                (skills_result[1]),
                                                skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[5])
                    character.set_cunning(Skill(ESkill.cunning,
                                                character.find_edice
                                                (skills_result[1]),
                                                skills_result[0]))

                    print(character.get_name() + "'s skills have "
                                                 "successfuly been "
                                                 "replaced.")
                except CharacterException as e:
                    print(e.value)
            except CharacterException as e:
                print(e.value)
        except InputException as e:
            print(e.value)