class Field: Nodes = [] FieldSizeX = 0 FieldSizeY = 0 #Get value method def __getitem__(self, pos): X, Y = pos return self.Nodes[X][Y].Value def __setitem__(self, pos, value, Type = "Value"): X, Y = pos if(Type == "Value"): self.Nodes[X][Y].Value = value else: self.Nodes[X][Y].Type = value def __init__(self, tilemap_types, tilemap_values): self.FieldSizeX = len(tilemap_types) - 1 self.FieldSizeY = len(tilemap_types[0]) - 1 if(tilemap_types != []): for x in range(0, self.FieldSizeX + 1): self.Nodes.append([]) for y in range(0, self.FieldSizeY + 1): node = Node(x, y, tilemap_types[x][y], tilemap_values[x][y]) self.Nodes[x].append(node) def get_type(self, pos): X, Y = pos return self.Nodes[X][Y].Type def PrintFieldTypes(self): for x in range(len(self.Nodes)): print() for y in range(len(self.Nodes[0])): print(self.Nodes[x][y].Type, end=' ') def PrintFieldValues(self): for x in range(len(self.Nodes)): print() for y in range(len(self.Nodes[0])): print(self.Nodes[x][y].Values, end=' ') def Neighbors(field, pos): x, y, dir = pos neighbors = [] if(x == 11): x = 11 if(x > 0 and field.get_type([x - 1, y]) != TREE and dir == 3): neighbors.append((x - 1, y, dir)) if(y > 0 and field.get_type([x, y - 1]) != TREE and dir == 0): neighbors.append((x, y - 1, dir)) if(x < field.FieldSizeX and field.get_type([x + 1, y]) != TREE and dir == 1): neighbors.append((x+1, y, dir)) if(y < field.FieldSizeY and field.get_type([x, y + 1]) != TREE and dir == 2): neighbors.append((x, y+1, dir)) neighbors.append((x, y, (dir + 1) % 4)) if(dir == 0): neighbors.append((x, y, 3)) else: neighbors.append((x, y, dir - 1)) return neighbors class Node: X = 0 Y = 0 Type = None Value = 0 def __init__(self, X, Y, Type, Value): self.X = X self.Y = Y self.Type = Type self.Value = Value SHORT = 1 TALL = 80 TREE = 100 SHORT_VALUE = 1 TALL_VALUE = 100 TREE_VALUE = 200 FLOWER_VALUE = 1