Esempio n. 1
0
    def set_trees(self, trees: List[Tree]) -> None:
        # =============================
        # INFORMATIONS :
        # -----------------------------
        # UTILITÉ :
        # Vérifie la cohérence de pluviometry_max puis l'assigne
        # -----------------------------
        # PRÉCONDITIONS (uniquement si DEBUG_MOD) :
        # - BIOME_PLUVIOMETRY_MIN <= pluviometry_max <= BIOME_PLUVIOMETRY_MAX
        # =============================
        if DEBUG_MOD:
            check_attribute_type_set(attribute_to_check=trees,
                                     type_to_check=list,
                                     name_of_attribute_to_check="_trees",
                                     object_destination=self)
            check_number_between_to_set(
                number_to_check=len(trees),
                min_value=BIOME_TREES_LEN_MIN,
                max_value=BIOME_TREES_LEN_MAX,
                name_of_attribute_to_check="len(_trees)",
                object_to_set=self)
            # Vérification que tous les éléments sont instance de Tree :
            i = 0
            while i < len(trees) and isinstance(trees[i], Tree):
                i += 1

            if i != len(trees):
                raise TypeError(
                    "Error: impossible to set _trees for a " +
                    type(self).__name__ + ":" +
                    "\n_trees must be a List[Tree] but element number " +
                    str(i) + " is a " + type(trees[i]).__name__ + ".")
        self._trees = trees
Esempio n. 2
0
 def set_x(self, x: int) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(attribute_to_check=x,
                                  type_to_check=int,
                                  name_of_attribute_to_check="_x",
                                  object_destination=self)
     self._x = x
Esempio n. 3
0
 def set_y(self, y: int) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(attribute_to_check=y,
                                  type_to_check=int,
                                  name_of_attribute_to_check="_y",
                                  object_destination=self)
     self._y = y
Esempio n. 4
0
 def set_biome(self, biome: Biome) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(attribute_to_check=biome,
                                  type_to_check=Biome,
                                  name_of_attribute_to_check="_biome",
                                  object_destination=self)
     self._biome = biome
Esempio n. 5
0
 def set_tree(self, tree: Tree) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(attribute_to_check=tree,
                                  type_to_check=Tree,
                                  name_of_attribute_to_check="_tree",
                                  object_destination=self)
     self._tree = tree
Esempio n. 6
0
 def set_position_in_tree(self, position_in_tree: Position) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=position_in_tree,
             type_to_check=Position,
             name_of_attribute_to_check="_position_in_tree",
             object_destination=self)
     self._position_in_tree = position_in_tree
Esempio n. 7
0
 def set_body(self, body: BoardColor) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=body,
             type_to_check=BoardColor,
             name_of_attribute_to_check="_body",
             object_destination=self
         )
     self._body = body
Esempio n. 8
0
 def set_name(self, name: str) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=name,
             type_to_check=str,
             name_of_attribute_to_check="_name",
             object_destination=self
         )
     self._name = name
Esempio n. 9
0
 def set_ground_color(self, ground_color: Color) -> None:
     # =============================
     # INFORMATIONS :
     # -----------------------------
     # UTILITÉ :
     # Vérifie la cohérence de ground_color puis l'assigne
     # =============================
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=ground_color,
             type_to_check=Color,
             name_of_attribute_to_check="_ground_color",
             object_destination=self)
     self._ground_color = ground_color
Esempio n. 10
0
    def set_elements(self, elements: List[List[Optional[Color]]]) -> None:
        if DEBUG_MOD:
            # Vérification que elements est bien un List[List[Optional[Color]]] :
            # Vérification que elements est bien un List
            check_attribute_type_set(attribute_to_check=elements,
                                     type_to_check=list,
                                     name_of_attribute_to_check="_elements",
                                     object_destination=self)

            # Vérification que elements est bien un List de quelque chose
            if len(elements) == 0:
                raise TypeError(
                    "Error: impossible to set _elements for a " +
                    type(self).__name__ + ":" +
                    "\n_elements must be a List[List[Optional[Color]], but an empty list is given."
                )
            # Vérification que elements est bien un List[List]
            i = 0
            while i < len(elements) and isinstance(elements[i], list):
                i += 1
            if i == len(elements):
                # Vérification que elements est bien un List[List[Optional[Color]
                line = 0
                column = 0
                while (line < len(elements)
                       and isinstance(elements[line], list) and column == 0):
                    while (column < len(elements[line])
                           and (elements[line][column] is None
                                or isinstance(elements[line][column], Color))):
                        column += 1
                    if column == len(elements[line]):
                        column = 0
                        line += 1

                if line != len(elements):
                    raise TypeError(
                        "Error: impossible to set _elements for a " +
                        type(self).__name__ + ":" +
                        "\n_elements must be a List[List[Optional[Color]] " +
                        "but at least one List[List]'s element is a " +
                        type(elements[line][column]).__name__ + ".")
            else:
                raise TypeError(
                    "Error: impossible to set _elements for a " +
                    type(self).__name__ + ":" +
                    "\n_elements must be a List[List[Optional[Color]]] " +
                    "but at least one List's element is not a List.")
        self._elements = elements
Esempio n. 11
0
 def set_red(self, red: int) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=red,
             type_to_check=int,
             name_of_attribute_to_check="_red",
             object_destination=self
         )
         check_number_between_to_set(
             number_to_check=red,
             min_value=COLOR_RGB_MIN,
             max_value=COLOR_RGB_MAX,
             name_of_attribute_to_check="_red",
             object_to_set=self
         )
     self._red = red
Esempio n. 12
0
 def set_green(self, green: int) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=green,
             type_to_check=int,
             name_of_attribute_to_check="_green",
             object_destination=self
         )
         check_number_between_to_set(
             number_to_check=green,
             min_value=COLOR_RGB_MIN,
             max_value=COLOR_RGB_MAX,
             name_of_attribute_to_check="_green",
             object_to_set=self
         )
     self._green = green
Esempio n. 13
0
 def set_spawn_probability(self, spawn_probability: float) -> None:
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=spawn_probability,
             type_to_check=float,
             name_of_attribute_to_check="_spawn_probability",
             object_destination=self
         )
         check_number_between_to_set(
             number_to_check=spawn_probability,
             min_value=0.0,
             max_value=1.0,
             name_of_attribute_to_check="_spawn_probability",
             object_to_set=self
         )
     self._spawn_probability = spawn_probability
Esempio n. 14
0
 def set_temperature_y(self, temperature_y: Optional[int]) -> None:
     if temperature_y is None:
         self._temperature_y = random.randint(SEED_ELEMENT_MIN,
                                              SEED_ELEMENT_MAX)
     else:
         if DEBUG_MOD:
             check_attribute_type_set(
                 attribute_to_check=temperature_y,
                 type_to_check=int,
                 name_of_attribute_to_check="_temperature_y",
                 object_destination=self)
             check_number_between_to_set(
                 number_to_check=temperature_y,
                 min_value=SEED_ELEMENT_MIN,
                 max_value=SEED_ELEMENT_MAX,
                 name_of_attribute_to_check="_temperature_y",
                 object_to_set=self)
         self._temperature_y = temperature_y
Esempio n. 15
0
 def set_pluviometry_x(self, pluviometry_x: Optional[int]) -> None:
     if pluviometry_x is None:
         self._pluviometry_x = random.randint(SEED_ELEMENT_MIN,
                                              SEED_ELEMENT_MAX)
     else:
         if DEBUG_MOD:
             check_attribute_type_set(
                 attribute_to_check=pluviometry_x,
                 type_to_check=int,
                 name_of_attribute_to_check="_pluviometry_x",
                 object_destination=self)
             check_number_between_to_set(
                 number_to_check=pluviometry_x,
                 min_value=SEED_ELEMENT_MIN,
                 max_value=SEED_ELEMENT_MAX,
                 name_of_attribute_to_check="_pluviometry_x",
                 object_to_set=self)
         self._pluviometry_x = pluviometry_x
Esempio n. 16
0
    def set_biomes(self, biomes: Dict[str, Biome]):
        if DEBUG_MOD:
            check_attribute_type_set(
                attribute_to_check=biomes,
                type_to_check=dict,
                name_of_attribute_to_check="_biomes",
                object_destination=self
            )
            # Vérification que tous les éléments de biomes sont instance de Biome
            iterator = iter(biomes)
            value = next(iterator, None)
            while value is not None and isinstance(biomes[value], Biome):
                value = next(iterator, None)

            if value is not None:
                raise TypeError(
                    "Error: impossible to set _biomes for a " + type(self).__name__ + ":" +
                    "\n_biomes must be a Dict[str, Biome] but at least one item is a " + type(value).__name__ + "."
                )
        self._biomes = biomes
Esempio n. 17
0
 def set_name(self, name: str) -> None:
     # =============================
     # INFORMATIONS :
     # -----------------------------
     # UTILITÉ :
     # Vérifie la cohérence de name puis le set
     # -----------------------------
     # PRÉCONDITIONS (uniquement si DEBUG_MOD) :
     # - BIOME_NAME_LEN_MIN <= len(name) <= BIOME_NAME_LEN_MAX
     # =============================
     if DEBUG_MOD:
         check_attribute_type_set(attribute_to_check=name,
                                  type_to_check=str,
                                  name_of_attribute_to_check="_name",
                                  object_destination=self)
         check_number_between_to_set(
             number_to_check=len(name),
             min_value=BIOME_NAME_LEN_MIN,
             max_value=BIOME_NAME_LEN_MAX,
             name_of_attribute_to_check="len(_name)",
             object_to_set=self)
     self._name = name
Esempio n. 18
0
 def set_pluviometry_max(self, pluviometry_max: float) -> None:
     # =============================
     # INFORMATIONS :
     # -----------------------------
     # UTILITÉ :
     # Vérifie la cohérence de pluviometry_max puis l'assigne
     # -----------------------------
     # PRÉCONDITIONS (uniquement si DEBUG_MOD) :
     # - BIOME_PLUVIOMETRY_MIN <= pluviometry_max <= BIOME_PLUVIOMETRY_MAX
     # =============================
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=pluviometry_max,
             type_to_check=float,
             name_of_attribute_to_check="_pluviometry_max",
             object_destination=self)
         check_number_between_to_set(
             number_to_check=pluviometry_max,
             min_value=BIOME_PLUVIOMETRY_MIN,
             max_value=BIOME_PLUVIOMETRY_MAX,
             name_of_attribute_to_check="_pluviometry_max",
             object_to_set=self)
     self._pluviometry_max = pluviometry_max
Esempio n. 19
0
 def set_temperature_max(self, temperature_max: float) -> None:
     # =============================
     # INFORMATIONS :
     # -----------------------------
     # UTILITÉ :
     # Vérifie la cohérence de temperature_max puis l'assigne
     # -----------------------------
     # PRÉCONDITIONS (uniquement si DEBUG_MOD) :
     # - BIOME_TEMPERATURE_MIN <= temperature_max <= BIOME_TEMPERATURE_MAX
     # =============================
     if DEBUG_MOD:
         check_attribute_type_set(
             attribute_to_check=temperature_max,
             type_to_check=float,
             name_of_attribute_to_check="_temperature_max",
             object_destination=self)
         check_number_between_to_set(
             number_to_check=temperature_max,
             min_value=BIOME_TEMPERATURE_MIN,
             max_value=BIOME_TEMPERATURE_MAX,
             name_of_attribute_to_check="_temperature_max",
             object_to_set=self)
     self._temperature_max = temperature_max