from plomrogue.errors import GameError, PlayError
from plomrogue.io import GameIO
from plomrogue.misc import quote
-from plomrogue.mapping import YX, MapGeometrySquare, Map
+from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex, Map
import string
super().set_line(*args, **kwargs)
self.modified = True
+ def inside(self, yx):
+ if yx.y < 0 or yx.x < 0 or \
+ yx.y >= self.geometry.size.y or yx.x >= self.geometry.size.x:
+ return False
+ return True
+
+ def draw_presets(self, alternate_hex=0):
+ old_modified = self.modified
+ if type(self.geometry) == MapGeometrySquare:
+ self.set_line(0, 'X' * self.geometry.size.x)
+ self.set_line(1, 'X' * self.geometry.size.x)
+ self.set_line(2, 'X' * self.geometry.size.x)
+ self.set_line(3, 'X' * self.geometry.size.x)
+ self.set_line(4, 'X' * self.geometry.size.x)
+ for y in range(self.geometry.size.y):
+ self[YX(y,0)] = 'X'
+ self[YX(y,1)] = 'X'
+ self[YX(y,2)] = 'X'
+ self[YX(y,3)] = 'X'
+ self[YX(y,4)] = 'X'
+ elif type(self.geometry) == MapGeometryHex:
+ # TODO: for this to work we need a map side length divisible by 6.
+
+ def draw_grid(offset=YX(0,0)):
+ dirs = ('DOWNRIGHT', 'RIGHT', 'UPRIGHT', 'RIGHT')
+
+ def draw_snake(start):
+ keep_running = True
+ yx = start
+ if self.inside(yx):
+ self[yx] = 'X'
+ while keep_running:
+ for direction in dirs:
+ if not keep_running:
+ break
+ for dir_progress in range(distance):
+ mover = getattr(self.geometry, 'move__' + direction)
+ yx = mover(yx)
+ if yx.x >= self.geometry.size.x:
+ keep_running = False
+ break
+ if self.inside(yx):
+ self[yx] = 'X'
+
+ if alternate_hex:
+ draw_snake(offset + YX(0, 0))
+ draw_snake(offset + YX((0 + alternate_hex) * distance, -int(1.5*distance)))
+ draw_snake(offset + YX((1 + alternate_hex) * distance, 0))
+ draw_snake(offset + YX((2 + alternate_hex) * distance, -int(1.5*distance)))
+
+ distance = self.geometry.size.y // 3
+ draw_grid()
+ draw_grid(YX(2,0))
+ draw_grid(YX(0,2))
+ draw_grid(YX(1,0))
+ draw_grid(YX(0,1))
+ draw_grid(YX(-1,0))
+ draw_grid(YX(0,-1))
+ draw_grid(YX(-2,0))
+ draw_grid(YX(0,-2))
+ self.modified = old_modified
+
import os
'o': 'sink',
'O': 'toilet'
}
- self.new_world(self.map_geometry)
if os.path.exists(self.io.save_file):
if not os.path.isfile(self.io.save_file):
raise GameError('save file path refers to non-file')
self.io.handle_input(line, god_mode=True)
def can_do_tile_with_pw(self, big_yx, little_yx, pw):
- map_control = self.get_map(big_yx)
+ map_control = self.get_map(big_yx, 'control')
tile_class = map_control[little_yx]
- if tile_class in self.map_control_passwords:
+ if tile_class in self.map_control_passwords.keys():
tile_pw = self.map_control_passwords[tile_class]
if pw != tile_pw:
return False
maps = self.map_controls
if not big_yx in maps:
maps[big_yx] = SaveableMap(self.map_geometry)
+ if type_ == 'control':
+ maps[big_yx].draw_presets(big_yx.y % 2)
return maps[big_yx]
def new_world(self, map_geometry):
+ self.maps = {}
+ self.map_controls = {}
+ self.annotations = {}
+ self.portals = {}
+ self.admin_passwords = []
self.map_geometry = map_geometry
- self.maps[YX(0,0)] = SaveableMap(self.map_geometry)
- self.map_controls[YX(0,0)] = SaveableMap(self.map_geometry)
+ self.map_control_passwords = {'X': 'secret'}
+ self.get_map(YX(0,0))
+ self.get_map(YX(0,0), 'control')
self.annotations = {}