Beispiel #1
0
    def create_point(self):
        # Add a new point
        mouse = pygame.mouse.get_pos()
        if self.is_space_available(mouse):
            self.points.append(Node.from_coord(mouse))

            self.evManager.post(Event.MapUpdatedEvent(self))
Beispiel #2
0
    def remove_point(self):
        # Remove the point and all lines connected to it
        mouse = pygame.mouse.get_pos()
        point_to_remove = self.get_point_selected(mouse)

        if point_to_remove is not None:
            self.points.remove(point_to_remove)

            for line in reversed(self.lines):
                if point_to_remove in line:
                    self.lines.remove(line)

            self.evManager.post(Event.MapUpdatedEvent(self))
Beispiel #3
0
    def create_line(self):
        for point in self.points:
            mouse = pygame.mouse.get_pos()
            if Map.is_point_selected(point, mouse):

                # First point selected
                if self.firstPoint is None:
                    self.firstPoint = point

                # Second point selected
                elif point != self.firstPoint and not self.is_crossing(
                        self.get_building_line()):

                    # Creation of a new line
                    self.lines.append([self.firstPoint, point])
                    self.firstPoint = None
                    self.evManager.post(Event.MapUpdatedEvent(self))
Beispiel #4
0
    def load_map(self, name):
        self.reset()

        with open(name, 'r') as file:
            for point in file.readline().split(' ')[:-1]:
                point = point.split(',')
                point = Node(int(point[0]), int(point[1]))
                self.points.append(point)

            for line in file.readlines():
                new_line = []
                for point in line.split(' ')[:-1]:
                    point = point.split(',')
                    point = Node(int(point[0]), int(point[1]))
                    new_line.append(point)
                self.lines.append(new_line)

        self.evManager.post(Event.MapUpdatedEvent(self))