2023-05-05 01:24:45 +02:00
|
|
|
|
|
|
|
class Field:
|
|
|
|
Nodes = []
|
|
|
|
FieldSizeX = 0
|
|
|
|
FieldSizeY = 0
|
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
#Get value method
|
2023-05-05 01:24:45 +02:00
|
|
|
def __getitem__(self, pos):
|
|
|
|
X, Y = pos
|
2023-05-22 10:18:32 +02:00
|
|
|
return self.Nodes[X][Y].Value
|
2023-05-05 01:24:45 +02:00
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
def __setitem__(self, pos, value, Type = "Value"):
|
2023-05-05 01:24:45 +02:00
|
|
|
X, Y = pos
|
2023-05-22 10:18:32 +02:00
|
|
|
if(Type == "Value"):
|
|
|
|
self.Nodes[X][Y].Value = value
|
|
|
|
else:
|
|
|
|
self.Nodes[X][Y].Type = value
|
2023-05-05 01:24:45 +02:00
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
def __init__(self, tilemap_types, tilemap_values):
|
|
|
|
self.FieldSizeX = len(tilemap_types) - 1
|
|
|
|
self.FieldSizeY = len(tilemap_types[0]) - 1
|
|
|
|
if(tilemap_types != []):
|
2023-05-05 01:24:45 +02:00
|
|
|
for x in range(0, self.FieldSizeX + 1):
|
|
|
|
self.Nodes.append([])
|
|
|
|
for y in range(0, self.FieldSizeY + 1):
|
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
node = Node(x, y, tilemap_types[x][y], tilemap_values[x][y])
|
2023-05-05 01:24:45 +02:00
|
|
|
self.Nodes[x].append(node)
|
2023-05-22 10:18:32 +02:00
|
|
|
|
|
|
|
def get_type(self, pos):
|
|
|
|
X, Y = pos
|
|
|
|
return self.Nodes[X][Y].Type
|
2023-05-05 01:24:45 +02:00
|
|
|
|
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
def PrintFieldTypes(self):
|
2023-05-05 01:24:45 +02:00
|
|
|
for x in range(len(self.Nodes)):
|
|
|
|
print()
|
|
|
|
for y in range(len(self.Nodes[0])):
|
|
|
|
print(self.Nodes[x][y].Type, end=' ')
|
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
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=' ')
|
|
|
|
|
|
|
|
|
2023-05-05 01:24:45 +02:00
|
|
|
def Neighbors(field, pos):
|
|
|
|
x, y, dir = pos
|
|
|
|
neighbors = []
|
|
|
|
if(x == 11):
|
|
|
|
x = 11
|
2023-05-22 10:18:32 +02:00
|
|
|
if(x > 0 and field.get_type([x - 1, y]) != TREE and dir == 3):
|
2023-05-05 01:24:45 +02:00
|
|
|
neighbors.append((x - 1, y, dir))
|
2023-05-22 10:18:32 +02:00
|
|
|
if(y > 0 and field.get_type([x, y - 1]) != TREE and dir == 0):
|
2023-05-05 01:24:45 +02:00
|
|
|
neighbors.append((x, y - 1, dir))
|
2023-05-22 10:18:32 +02:00
|
|
|
if(x < field.FieldSizeX and field.get_type([x + 1, y]) != TREE and dir == 1):
|
2023-05-05 01:24:45 +02:00
|
|
|
neighbors.append((x+1, y, dir))
|
2023-05-22 10:18:32 +02:00
|
|
|
if(y < field.FieldSizeY and field.get_type([x, y + 1]) != TREE and dir == 2):
|
2023-05-05 01:24:45 +02:00
|
|
|
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
|
2023-05-22 10:18:32 +02:00
|
|
|
Value = 0
|
2023-05-05 01:24:45 +02:00
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
def __init__(self, X, Y, Type, Value):
|
2023-05-05 01:24:45 +02:00
|
|
|
self.X = X
|
|
|
|
self.Y = Y
|
|
|
|
self.Type = Type
|
2023-05-22 10:18:32 +02:00
|
|
|
self.Value = Value
|
2023-05-05 01:24:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
SHORT = 1
|
|
|
|
TALL = 80
|
|
|
|
TREE = 100
|
|
|
|
|
2023-05-22 10:18:32 +02:00
|
|
|
SHORT_VALUE = 1
|
|
|
|
TALL_VALUE = 100
|
|
|
|
TREE_VALUE = 100
|
2023-05-05 01:24:45 +02:00
|
|
|
|