Example #1
0
    def init_moove(self, hero_coords, directions, tp, victory):
        """Initalization of the movement.

        Create a list of coordinates.
        """
        self.tp = csc.transform_coords_to('string', tp) if tp else None
        self.victory = victory

        self.v_x = 0
        self.v_y = 0
        self.index = 0
        self.list_coords = []

        self.activated = True
        self.hero_coords = hero_coords

        x, y = hero_coords
        for letter in directions:

            if letter == "l":
                x -= 64
            elif letter == "r":
                x += 64
            elif letter == "t":
                y -= 64
            elif letter == "d":
                y += 64

            self.list_coords.append(((x, y), letter))

        self.init_direction()
Example #2
0
 def activate(self, coords, name):
     """Activate the teleportation."""
     self.coords = csc.transform_coords_to('string', coords)
     self.activated = True
     self.index = 0
     self.key = 'starting'
     self.name = name
Example #3
0
    def update(self):
        """Moove the active hero.

        Return a message who contains the new hero's coordinates.
        """
        if not self.activated:
            return ""

        msg = 'moove:'

        if self.hero_coords == self.list_coords[self.index][0]:
            self.index += 1

            if self.index == len(self.list_coords):
                self.activated = False
                msg += "end "

                if self.victory:
                    msg += " victory! "
                elif self.tp:
                    msg += f" teleportation:{self.tp} "
                return msg

            self.init_direction()

        x, y = self.hero_coords
        a, b = self.v_x, self.v_y
        x += a
        y += b
        self.hero_coords = x, y

        msg += csc.transform_coords_to('string', self.hero_coords)

        return msg if msg != 'moove:' else ''
Example #4
0
    def __init__(self, image, coords):
        """Initialization."""
        super().__init__()

        self.image = image
        self.coords = coords

        self.rect = self.image.get_rect()
        self.rect.x, self.rect.y = csc.transform_coords_to('real', self.coords)
Example #5
0
    def active_the_pathfinding(self, mouse, case_group):
        """Activate the pathfinding research."""
        if not mouse:  # If the mouse is over the map/game.
            return

        abstract_mouse = csc.transform_coords_to('abstract', mouse)
        if abstract_mouse == self._mouse:  # If the mouse is on the same case.
            return

        self._mouse = abstract_mouse
        self._calcul_a_new_path(case_group)
Example #6
0
def find_and_get_coords_after(sub_message, message):
    """Return coordinates after the sub_message.

    get the string version of coordinates then transform it into tuple.
    """
    index = message.find(sub_message) + len(sub_message)
    string_coordinates = message[index:index + 9]

    coordinates = transform_coords_to('tuple', string_coordinates)

    return coordinates
Example #7
0
    def test_transform_coords(self, number_of_tests=10):
        """Test the transfom_coord_to function.

        We start with a random abstract coordinates,
        made with the random's module.
        max x and y doesn't exceed the sizes of my maps (20 on 9)

        - real_coords must be equal to abstract coords * the size of the cases.

        - return to abstract must be equal to the first abstract variable.

        - size of string coord must be equal to 10.
        - string coords and tuple coords must be str and tuple.

        - the last coords variable must be equal to the first..!

        - finally, we transform real coords to str, and return it to tuple.
        - we test if the tuple didn t change after the transformation.

        After that, call the test again,
        until the parameter 'test number' equals 1.
        """
        coords = (random.randint(0, 19), random.randint(0, 8))
        print("test of 'transform_coords_to'. start coords is ", coords)

        real_coords = transform_coords_to('real', coords)
        x, y = coords
        self.assertEqual((x * CASE_SIZE, y * CASE_SIZE), real_coords)

        abstract_coords = transform_coords_to('abstract', real_coords)
        self.assertEqual(abstract_coords, coords)

        string_coords = transform_coords_to('string', abstract_coords)
        self.assertEqual(10, len(string_coords))
        self.assertIsInstance(string_coords, str)

        tuple_coords = transform_coords_to('tuple', string_coords)
        self.assertIsInstance(tuple_coords, tuple)
        self.assertEqual(tuple_coords, coords)

        string_real_coords = transform_coords_to('string', real_coords)
        tuple_real_coords = transform_coords_to('tuple', string_real_coords)
        self.assertEqual(tuple_real_coords, real_coords)

        if number_of_tests > 1:
            self.test_transform_coords(number_of_tests=number_of_tests - 1)
Example #8
0
    def activate(self, coords):
        """Event activation."""
        self.activated = True
        self.s_coords = csc.transform_coords_to('string', coords)

        return f"transform: activated coords:{self.s_coords}"
Example #9
0
 def define_coords(self, coords):
     """Define the coordinates."""
     self.rect.x, self.rect.y = csc.transform_coords_to('real', coords)
Example #10
0
 def abstract_coords(self):
     """Get abstract coords."""
     return csc.transform_coords_to('abstract', self.coords)
Example #11
0
    def start(self, event, mouse):
        """Start the events."""
        hero = self.game.active_player
        pathfinder = self.game.sprt.pathfinder
        c_grp = self.game.sprt.cases_group

        if self.game.victory:
            if event.type == MOUSEBUTTONDOWN and event.button == 1:
                button = self.game.sprt.victory.button
                if button.rect.collidepoint(mouse):
                    self.game.go_to = 'main_menu'
            return

        if not self.game.active_turn or self.game.in_action:
            return

        if event.type == MOUSEBUTTONDOWN and event.button == 1:
            self.transform_vision = False

            for button in self.mlr2:
                if button.rect.collidepoint(mouse):
                    if button.name == 'bull':
                        self.game.msg += "next_turn"
                        button.activated = True
                    if button.name == 'transform' and hero.transform_spell:
                        button.activated = True
                        if not self.transform_vision:
                            self.transform_vision = True

            if hero.transform_spell and self.game.sprt.transform_paths:

                for case in self.game.sprt.transform_paths:
                    if case.rect.collidepoint(mouse):
                        hero.transform_spell = False
                        self.game.sprt.transform.desactivated = True
                        coords = csc.transform_coords_to('string', case.coords)
                        self.game.msg += "transform:" + coords
                        self.game.in_action = True
                        return

            if hero.has_moove and pathfinder:

                for case in pathfinder:
                    if case.rect.collidepoint(mouse):
                        hero.actual_moove -= case.distance
                        coords_path = [case.coords for case in pathfinder]
                        str_moove = "moove:"
                        c = csc.transform_coords_to('string', hero.coords)
                        str_moove += "hero_coords:" + c
                        len_coords = len(coords_path) - 1
                        str_moove += f"len:{len_coords},directions:"

                        for i, coords in enumerate(coords_path):
                            if i == len(coords_path) - 1:
                                break

                            x = coords[0]
                            y = coords[1]
                            a = coords_path[i + 1][0]
                            b = coords_path[i + 1][1]
                            if x < a:
                                str_moove += "r"
                            elif x > a:
                                str_moove += "l"
                            elif y < b:
                                str_moove += "d"
                            elif y > b:
                                str_moove += "t"
                            else:
                                raise ValueError("Target case == current.")

                        last_c = coords_path[-1]
                        coords = csc.transform_coords_to('real', last_c)

                        if c_grp[last_c].nature == "teleporter":
                            coords = c_grp.find_another_teleporter(coords)
                            coords = csc.transform_coords_to('string', coords)
                            str_moove += f" teleporter:{coords} "

                        elif c_grp[last_c].nature == "victory":
                            str_moove += " victory "

                        self.game.msg += str_moove
                        return
Example #12
0
 def true_coords(self):
     """Return reals coords."""
     return csc.transform_coords_to('real', self.coords)