示例#1
0
class Boat:
    def __init__(self):
        try:
            type(self._location)
        except AttributeError:
            self._location = Location()

    #GETTERS/SETTERS

    def get_location(self):
        return self._location

    def set_location(self, pos, orientation, constraints):
        self._location.set_location(pos, orientation=orientation, constraints=constraints)
        return self

    #OPERATORS OVERLOADERS
    def __str__(self):
        return ' '

    def __len__(self):
        return len(self._location)

    def __bool__(self):
        return bool(self._location)

    def __contains__(self, other):
        if not self or not other:
            return False
        return self.get_location() in other.get_location()

    #VIEWS

    def view_set_location(self, boats):
        self._location.view_init_location(boats)
示例#2
0
class Shoot:
    def __init__(self):
        self._location = Location()
        self._status = None

    #GETTERS/SETTERS

    def get_location(self):
        return self._location

    def set_location(self, pos):
        self._location.set_location(pos)
        return self

    def get_status(self):
        return self._status

    #VIEW

    def view_set_location(self):
        self._location.view_init_location()

    #OPERATORS OVERLOADERS

    def __bool__(self):
        return bool(self._location)

    def __contains__(self, other):
        if not self or not other:
            return False
        return self.get_location() in other.get_location()

    def __iadd__(self, other):
        if type(other) not in [ShootFailed, ShootSuccessful]:
            raise TypeError("Type of the second member is not allowed")
        if not self:
            raise ValueError("Shoot has no location")
        other.set_location(self.get_location().get_pos())
        return other
示例#3
0
 def __init__(self):
     self._location = Location()
     self._status = None
示例#4
0
 def __init__(self):
     try:
         type(self._location)
     except AttributeError:
         self._location = Location()