コード例 #1
0
    def universe_max_locationZZZ(self):
        """
        Returns the location of a point that creates a box with the origin and contains all objects
        :return:
        """
        max_loc = Location(0, 0, 0)
        for star in self.star_list():
            if star.location.x > max_loc.x:
                max_loc.x = star.location.x

            if star.location.y > max_loc.y:
                max_loc.y = star.location.y

            if star.location.z > max_loc.z:
                max_loc.z = star.location.z

        # TODO iterate on ships for max location too (although I don't want to make ships go away from furthest star)

        return max_loc
コード例 #2
0
    def update_from_star(self, s: 'Star'):
        # YES, update the ID.  If its a kafka update, it'll stay the same, but if its hovered/selected it'll update
        if s is None:
            self._star_id = -1
            self._name = ""
            self._location = Location(0, 0, 0)
        else:
            self._star_id = s.star_id()
            self._name = s.name()
            self._location = s.location()

        self.notify_observers()
コード例 #3
0
def create_random_stars(num_stars, universe_size, minimum_distance) -> List[Star]:
    stars = []
    print("starting create_random_stars")
    while len(stars) < num_stars:
        star_id = len(stars) + 1
        name = "Star-{0}".format(star_id)
        location = None

        attempt_count = 0
        max_attempts = 1000

        found_safe_spot = False
        while attempt_count < max_attempts and not found_safe_spot:
            print("iterating an attempt")
            location = Location(
                random.randint(-1 * universe_size[0], universe_size[0]),
                random.randint(-1 * universe_size[1], universe_size[1]),
                0
            )

            for star in stars:
                if Location.distance(location, star.location()) <= minimum_distance:
                    break

            # if we made it here, we found a safe spot
            print("setting found_safe_spot to True")
            found_safe_spot = True

        if found_safe_spot:
            print("found safe spot, adding star to list")
            stars.append(Star(star_id, name, location))
        else:
            # we iterated until max_attempts and STILL didnt find a nice location
            print("Iterated {0} times and did NOT find a nice location, returning the stars I have".format(len(stars)))
            break


    print("ending create_random_stars {0}".format(len(stars)))
    return stars
コード例 #4
0
ファイル: star_gui.py プロジェクト: esasiela/hc-space-haul
    def observable_update(self, o, e=None):
        if isinstance(e, SpaceHaulControllerEvent):
            if e.event_type == "hover" and isinstance(e.o, Star):
                e.o.add_observer(self)
                self.star_change_comm.signal.emit(e.o)

            elif e.event_type == "unhover" and isinstance(e.o, Star):
                e.o.remove_observer(self)
                self.star_change_comm.signal.emit(Star(-1, "", Location(0, 0, 0)))

        elif isinstance(o, Star):
            # the hovered star changed attributes
            self.star_change_comm.signal.emit(o)
コード例 #5
0
ファイル: ship.py プロジェクト: esasiela/hc-space-haul
    def update_from_ship(self, s: 'Ship'):
        # YES, update the ID.  If its a kafka update, it'll stay the same, but if its hovered/selected it'll update
        if s is None:
            self._ship_id = -1
            self._name = ""
            self._location = Location(0, 0, 0)
            self._docked_star = None
            self._departure_star = None
            self._destination_star = None
        else:
            self._ship_id = s.ship_id()
            self._name = s.name()
            self._location = s.location()

            if s.docked_star() is not None and (
                self.docked_star() is None or
                s.docked_star().star_id() != self.docked_star().star_id()
            ):
                self.set_docked_star(s.docked_star())
            else:
                self.set_docked_star(None)

            if s.destination_star() is not None and (
                self.destination_star() is None or
                s.destination_star().star_id() != self.destination_star().star_id()
            ):
                self.set_destination_star(s.destination_star())
            else:
                self.set_destination_star(None)

            if s.departure_star() is not None and (
                self.departure_star() is None or
                s.departure_star().star_id() != self.departure_star().star_id()
            ):
                self.set_departure_star(s.departure_star())
            else:
                self.set_departure_star(None)

        self.notify_observers()
コード例 #6
0
ファイル: ship.py プロジェクト: esasiela/hc-space-haul
    def from_dict(cls, d, star_list: StarList):
        s = Ship(d["_ship_id"], d["_name"], Location.from_dict(d["_location"]))

        if d["_docked_star"] is not None:
            # find the star in the StarList by ID
            for star in star_list.stars():
                if star.star_id() == d["_docked_star"]:
                    s.set_docked_star(star)

        if d["_destination_star"] is not None:
            # find the star in the StarList by ID
            for star in star_list.stars():
                if star.star_id() == d["_destination_star"]:
                    s.set_destination_star(star)

        if d["_departure_star"] is not None:
            # find the star in the StarList by ID
            for star in star_list.stars():
                if star.star_id() == d["_departure_star"]:
                    s.set_departure_star(star)

        return s
コード例 #7
0
            print("found safe spot, adding star to list")
            stars.append(Star(star_id, name, location))
        else:
            # we iterated until max_attempts and STILL didnt find a nice location
            print("Iterated {0} times and did NOT find a nice location, returning the stars I have".format(len(stars)))
            break


    print("ending create_random_stars {0}".format(len(stars)))
    return stars


if __name__ == "__main__":
    print("Publishing a star to kafka...")

    gummerton = Star(1, "Gummerton", Location(-600000, 100, 0))
    new_gumbria = Star(2, "New Gumbria", Location(500000, -600000, 0))
    gummi_glen = Star(3, "Gummi Glen", Location(300000, 300000, 0))
    stars = [
        gummerton,
        new_gumbria,
        gummi_glen
    ]

    gss_toadie = Ship(1, "GSS Toadie", Location(gummerton.location().x, gummerton.location().y, gummerton.location().z))
    print("first gss_toadie.location()", gss_toadie.location())
    ships = [
        gss_toadie
    ]

    stars = create_random_stars(2, (700000, 700000, 0), 100000)
コード例 #8
0
 def from_dict(cls, d):
     return Star(d["_star_id"], d["_name"],
                 Location.from_dict(d["_location"]))