Intelegentny_Pszczelarz/src/Field.py

73 lines
1.7 KiB
Python
Raw Normal View History

2023-05-05 01:24:45 +02:00
class Field:
Nodes = []
FieldSizeX = 0
FieldSizeY = 0
def __getitem__(self, pos):
X, Y = pos
return self.Nodes[X][Y].Type
def __setitem__(self, pos, value):
X, Y = pos
self.Nodes[X][Y].Type = value
def __init__(self, tilemap):
self.FieldSizeX = len(tilemap) - 1
self.FieldSizeY = len(tilemap[0]) - 1
if(tilemap != []):
for x in range(0, self.FieldSizeX + 1):
self.Nodes.append([])
for y in range(0, self.FieldSizeY + 1):
node = Node(x, y, tilemap[x][y])
self.Nodes[x].append(node)
def PrintField(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 Neighbors(field, pos):
x, y, dir = pos
neighbors = []
if(x == 11):
x = 11
if(x > 0 and field[x - 1, y] != TREE and dir == 3):
neighbors.append((x - 1, y, dir))
if(y > 0 and field[x, y - 1] != TREE and dir == 0):
neighbors.append((x, y - 1, dir))
if(x < field.FieldSizeX and field[x + 1, y] != TREE and dir == 1):
neighbors.append((x+1, y, dir))
if(y < field.FieldSizeY and field[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
def __init__(self, X, Y, Type):
self.X = X
self.Y = Y
self.Type = Type
SHORT = 1
TALL = 80
TREE = 100