generated from mwc/project_game
131 lines
4.3 KiB
Python
131 lines
4.3 KiB
Python
from common import HOR_SEP_LEN, VER_SEP_LEN, PAD
|
|
|
|
|
|
class Tile:
|
|
def __init__(self, path, step):
|
|
self.path = path
|
|
self.step = step
|
|
self.name = f'{path}_{step}'
|
|
self.character = 'o'
|
|
self.make_position()
|
|
self.make_big_tile()
|
|
self.z = 1
|
|
|
|
def make_big_tile(self):
|
|
peri_big = self.path == 'peri' and self.step in [0, 5, 10, 15]
|
|
diag_big = self.path.startswith('diag') and self.step == 3
|
|
if peri_big or diag_big:
|
|
self.character = 'O'
|
|
self.color = 'purple'
|
|
|
|
def make_position(self):
|
|
min_x = PAD
|
|
max_x = PAD + (HOR_SEP_LEN + 1) * 5
|
|
min_y = PAD
|
|
max_y = PAD + (VER_SEP_LEN + 1) * 5
|
|
x_step = HOR_SEP_LEN + 1
|
|
y_step = VER_SEP_LEN + 1
|
|
if self.path == 'peri':
|
|
if self.step <= 5:
|
|
x = min_x + x_step * self.step
|
|
y = max_y
|
|
elif self.step <= 10:
|
|
x = max_x
|
|
y = min_y + y_step * (10 - self.step)
|
|
elif self.step <= 15:
|
|
x = min_x + x_step * (15 - self.step)
|
|
y = PAD
|
|
elif self.step <= 19:
|
|
x = min_x
|
|
y = min_y + y_step * (self.step - 15)
|
|
|
|
if self.path == 'diag1':
|
|
if self.step == 1:
|
|
x = max_x - (HOR_SEP_LEN + 1)
|
|
y = min_y + (VER_SEP_LEN + 1)
|
|
else:
|
|
x = max_x - (HOR_SEP_LEN + 1) - HOR_SEP_LEN*(self.step - 1)
|
|
y = min_y + (VER_SEP_LEN + 1) + VER_SEP_LEN*(self.step - 1)
|
|
|
|
if self.path == 'diag2':
|
|
if self.step == 1:
|
|
x = max_x - (HOR_SEP_LEN + 1)
|
|
y = max_y - (VER_SEP_LEN + 1)
|
|
else:
|
|
x = max_x - (HOR_SEP_LEN + 1) - HOR_SEP_LEN*(self.step - 1)
|
|
y = max_y - (VER_SEP_LEN + 1) - VER_SEP_LEN*(self.step - 1)
|
|
|
|
self.position = (x, y)
|
|
|
|
|
|
class Separator:
|
|
def __init__(self, kind, position):
|
|
chars = {
|
|
'hor': '-',
|
|
'ver': '|',
|
|
'diagr': '/',
|
|
'diagl': '\\',
|
|
}
|
|
self.character = chars[kind]
|
|
self.position = position
|
|
self.z = 0
|
|
|
|
|
|
def make_board():
|
|
agents = []
|
|
|
|
#Perimeter loop
|
|
peri_agents = [Tile('peri', step) for step in range(20)]
|
|
agents.extend(peri_agents)
|
|
|
|
# First diagonal
|
|
diag1_agents = [Tile('diag1', step) for step in range(1, 6)]
|
|
agents.extend(diag1_agents)
|
|
|
|
# Second diagonal
|
|
diag2_agents = [Tile('diag2', step) for step in range(1, 6)]
|
|
agents.extend(diag2_agents)
|
|
|
|
# Separators
|
|
agents.extend(make_separators(peri_agents))
|
|
agents.extend(make_separators(diag1_agents))
|
|
agents.extend(make_separators(diag2_agents))
|
|
|
|
# Manually add the remaining separators
|
|
agents.extend([Separator('diagr', (PAD+i, PAD - i + (VER_SEP_LEN + 1) * 5)) for i in range(1, HOR_SEP_LEN + 1)])
|
|
agents.extend([Separator('diagr', (PAD+(HOR_SEP_LEN+1)*5 - i, PAD + i)) for i in range(1, VER_SEP_LEN + 1)])
|
|
agents.extend([Separator('diagl', (PAD+i, PAD + i)) for i in range(1, HOR_SEP_LEN + 1)])
|
|
agents.extend([Separator('diagl', (PAD+(HOR_SEP_LEN+1)*5 - i, PAD + (VER_SEP_LEN+1) * 5 - i)) for i in range(1, VER_SEP_LEN + 1)])
|
|
|
|
|
|
return agents
|
|
|
|
|
|
def make_separators(tiles):
|
|
agents = []
|
|
for i in range(len(tiles)):
|
|
this_tile = tiles[i]
|
|
if i == len(tiles)-1:
|
|
next_tile = tiles[0]
|
|
else:
|
|
next_tile = tiles[i+1]
|
|
x0 = this_tile.position[0]
|
|
y0 = this_tile.position[1]
|
|
|
|
dx = next_tile.position[0] - x0
|
|
dy = next_tile.position[1] - y0
|
|
|
|
if dx > 0 and dy == 0:
|
|
agents.extend([Separator('hor', (x0+1+step, y0)) for step in range(HOR_SEP_LEN)])
|
|
if dx < 0 and dy == 0:
|
|
agents.extend([Separator('hor', (x0-1-step, y0)) for step in range(HOR_SEP_LEN)])
|
|
if dx == 0 and dy > 0:
|
|
agents.extend([Separator('ver', (x0, y0+1+step)) for step in range(VER_SEP_LEN)])
|
|
if dx == 0 and dy < 0:
|
|
agents.extend([Separator('ver', (x0, y0-1-step)) for step in range(VER_SEP_LEN)])
|
|
if dx < 0 and dy > 0:
|
|
|
|
agents.extend([Separator('diagr', (x0-1-step, y0+1+step)) for step in range(VER_SEP_LEN)])
|
|
if dx < 0 and dy < 0:
|
|
agents.extend([Separator('diagl', (x0-1-step, y0-1-step)) for step in range(VER_SEP_LEN)])
|
|
return agents |