Esempio n. 1
0
    def MassRemoveFromWorld(self, s, p, foo):

        x = 0 if p.x - 1 < 0 else p.x - 1
        y = 0 if p.y - 1 < 0 else p.y - 1

        yMax = p.x if p.x + 1 == self.__board.row else p.x + 1
        xMax = p.y if p.y + 1 == self.__board.col else p.y + 1

        temp = Point(0, 0)

        for i in range(x, xMax + 1):
            for j in range(y, yMax + 1):
                if (i == p.x) and (y == p.y):
                    continue

                temp.set(i, j)

                o = self.__board.GetAt(temp)
                if o == None:
                    continue

                if foo(o) == False:
                    continue
                else:
                    o.Kill(s)
Esempio n. 2
0
    def __GetButtonIndex(self, b):
        p = Point(0, 0)
        index = self.__buttons.index(b)

        p.x = index % self.__width
        p.y = index // self.__width

        return p
Esempio n. 3
0
    def Save(self, e):

        f = open("C:/Users/abc/source/repos/PythonApplication1/PythonApplication1/General/Resources/save.txt", "w")

        #saving
        self.Notify("Saving...")

        #world
        f.write("%d\n" %self.__organismsC)

        #board
        f.write("%d\n%d\n" %(self.__board.row, self.__board.col))

        p = Point(0, 0)

		#organisms
        for y in range(self.__board.row):
            for x in range(self.__board.col):
                p.set(x, y)
                o = self.GetAt(p)

                if o == None:
                     f.write("%d\n" %0)
                else:
                    f.write("%d\n%c\n%d\n%d\n" %(1, o.token, o.age, o.strength))

        #born
        f.write("%d\n" %len(self.__born))
        for o in self.__born:
            if o == None:
                f.write("%d\n" %0)
            else:
                f.write("%d\n%d\n%d\n" %(1, o.location.x, o.location.y))

        #dead
        f.write("%d\n" %len(self.__dead))
        for o in self.__dead:
            if o == None:
                f.write("%d\n" %0)
            else:
                f.write("%d\n%d\n%d\n" %(1, o.location.x, o.location.y))

        f.write("%d\n%d" %(self.__player.cooldown, self.__player.duration))

        f.close()
        self.Notify("Saving complete!")
Esempio n. 4
0
    def Translate(p, dir):
        if dir == WorldDirections.DIR_NULL:
            dir = WorldDirections(Utilities.randomInt(0, WorldDirections.DIRECTIONS_COUNT.value - 1));

        x = p.x
        y = p.y

        point = Point(x, y)
        
        switcher = {
            WorldDirections.NORTH : lambda a, b : (a, b - 1),
            WorldDirections.EAST  : lambda a, b : (a + 1, b),
            WorldDirections.SOUTH : lambda a, b : (a, b + 1),
            WorldDirections.WEST  : lambda a, b : (a - 1, b)
            }
        
        func = switcher.get(dir, lambda a, b : (a, b))
        x, y = func(x, y)
        point.set(x, y)

        return point
Esempio n. 5
0
    def SetAt(self, o):

        self.__seekBuffer.clear()

        for x in range(self.row):
            for y in range(self.col):
                
                temp = Point(x, y)

                if self.__organisms[self.__index(temp)] == None:
                    self.__seekBuffer.append(temp)

        if len(self.__seekBuffer) == 0:
            return

        if o.location != Navigation.NULL_POINT:
            self.__organisms[self.__index(o.location)] = None

        temp = self.__seekBuffer[Utilities.randomInt(0, len(self.__seekBuffer) - 1)]

        o.location = temp
        self.__organisms[self.__index(temp)] = o
Esempio n. 6
0
    def SeekForFree(self, p):
        self.__seekBuffer.clear()

        x = 0 if p.x - 1 < 0 else p.x - 1
        y = 0 if p.y - 1 < 0 else p.y - 1

        yMax = p.x if p.x + 1 == self.row else p.x + 1
        xMax = p.y if p.y + 1 == self.col else p.y + 1

        for i in range(x, xMax + 1):
            for j in range(y, yMax + 1):

                if (i == p.x) and (j == p.y):
                    continue

                temp = Point(i, j)

                if self.__organisms[self.__index(temp)] == None:
                    self.__seekBuffer.append(temp)

        if len(self.__seekBuffer) == 0:
            return Navigation.NULL_POINT

        return self.__seekBuffer[Utilities.randomInt(0, len(self.__seekBuffer) - 1)]
Esempio n. 7
0
 def NavigationInit():
     Navigation.NULL_POINT = Point(-1, -1)
Esempio n. 8
0
    def Load(self, e):

        f = open("C:/Users/abc/source/repos/PythonApplication1/PythonApplication1/General/Resources/save.txt", "r")

        #loading
        self.Notify("Loading...")

        i1 = int(f.readline())
        self.age = i1

        #board
        i1 = int(f.readline())
        i2 = int(f.readline())

        self.layout.Build(i1, i2)

        self.__born.clear()
        self.__dead.clear()

        #organisms
        for y in range(self.__board.row):
            for x in range(self.__board.col):
                p = Point(x, y)

                i1 = int(f.readline())

                if i1 == 0:
                    continue
                else:
                    t = f.readline()[0]
                    i2 = int(f.readline())
                    i3 = int(f.readline())

                    o = Entities.CreateChar(t)
                    o.world = self
                    o.age = i2
                    o.strength = i3
                    o.location = p

                    self.AddToWorld(o, p)

        self.__board.Print()

        #born
        i1 = int(f.readline())
        for i in range(i1):
            i2 = int(f.readline())
            if i2 == 0:
                continue
            else:
                i3 = int(f.readline())
                i4 = int(f.readline())

                p = Point(i3, i4)

                self.__born.append(self.GetAt(p))

        #dead
        i1 = int(f.readline())
        for i in range(i1):
            i2 = int(f.readline())
            if i2 == 0:
                continue
            else:
                i3 = int(f.readline())
                i4 = int(f.readline())

                p = Point(i3, i4)

                self.__dead.append(self.GetAt(p))

        i1 = int(f.readline())
        i2 = int(f.readline())

        self.__player.SetActive(i1, i2)

        f.close()
        self.__ClearLegend()
        self.Notify("Loading complete!")