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)
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!")
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