from plomrogue.parser import ArgError, Parser
from plomrogue.commands import cmd_MAP, cmd_THING_POS, cmd_PLAYER_ID
from plomrogue.game import Game, WorldBase
-from plomrogue.mapping import MapBase
+from plomrogue.mapping import MapHex
from plomrogue.io import PlomSocket
from plomrogue.things import ThingBase
import types
import queue
-class Map(MapBase):
+class ClientMap(MapHex):
def y_cut(self, map_lines, center_y, view_height):
map_height = len(map_lines)
on any update, even before we actually receive map data.
"""
super().__init__(*args, **kwargs)
- self.map_ = Map()
+ self.map_ = ClientMap()
self.player_inventory = []
self.player_id = 0
self.pickable_items = []
def new_map(self, yx):
- self.map_ = Map(yx)
+ self.map_ = ClientMap(yx)
@property
def player(self):
class MapWidget(Widget):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.examine_mode = False
+ self.examine_pos = (0, 0)
+
def draw(self):
def annotated_terrain():
terrain_as_list[pos_i] = (symbol, '+')
else:
terrain_as_list[pos_i] = symbol
+ if self.examine_mode:
+ pos_i = self.tui.game.world.map_.\
+ get_position_index(self.examine_pos)
+ terrain_as_list[pos_i] = (terrain_as_list[pos_i][0], '?')
return terrain_as_list
def pad_or_cut_x(lines):
annotated_terrain = annotated_terrain()
center = self.tui.game.world.player.position
+ if self.examine_mode:
+ center = self.examine_pos
lines = self.tui.game.world.map_.format_to_view(annotated_terrain,
center, self.size)
pad_or_cut_x(lines)
self.item_pointer = len(selectables) - 1
if key == 'c':
switch_widgets(widget, map_widget)
+ map_widget.examine_mode = False
elif key == 'j':
self.item_pointer += 1
elif key == 'k' and self.item_pointer > 0:
trigger = widget.check_updates[0]
self.to_update[trigger] = True
+ def move_examiner(direction):
+ start_pos = map_widget.examine_pos
+ new_examine_pos = self.game.world.map_.move(start_pos, direction)
+ if new_examine_pos:
+ map_widget.examine_pos = new_examine_pos
+ self.to_update['map'] = True
+
setup_screen(stdscr)
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)
for w in top_widgets:
w.ensure_freshness(True)
elif map_widget.visible:
- if key == 'w':
+ if key == '?':
+ map_widget.examine_mode = not map_widget.examine_mode
+ map_widget.examine_pos = self.game.world.player.position
+ self.to_update['map'] = True
+ elif key == 'p':
+ self.socket.send('GET_PICKABLE_ITEMS')
+ self.item_pointer = 0
+ switch_widgets(map_widget, pickable_items_widget)
+ elif key == 'i':
+ self.item_pointer = 0
+ switch_widgets(map_widget, inventory_widget)
+ elif map_widget.examine_mode:
+ if key == 'w':
+ move_examiner('UPLEFT')
+ elif key == 'e':
+ move_examiner('UPRIGHT')
+ elif key == 's':
+ move_examiner('LEFT')
+ elif key == 'd':
+ move_examiner('RIGHT')
+ elif key == 'x':
+ move_examiner('DOWNLEFT')
+ elif key == 'c':
+ move_examiner('DOWNRIGHT')
+ elif key == 'w':
self.socket.send('TASK:MOVE UPLEFT')
elif key == 'e':
self.socket.send('TASK:MOVE UPRIGHT')
- if key == 's':
+ elif key == 's':
self.socket.send('TASK:MOVE LEFT')
elif key == 'd':
self.socket.send('TASK:MOVE RIGHT')
- if key == 'x':
+ elif key == 'x':
self.socket.send('TASK:MOVE DOWNLEFT')
elif key == 'c':
self.socket.send('TASK:MOVE DOWNRIGHT')
- elif key == 'p':
- self.socket.send('GET_PICKABLE_ITEMS')
- self.item_pointer = 0
- switch_widgets(map_widget, pickable_items_widget)
- elif key == 'i':
- self.item_pointer = 0
- switch_widgets(map_widget, inventory_widget)
elif pickable_items_widget.visible:
pick_or_drop_menu('p', pickable_items_widget,
self.game.world.pickable_items,
-class MapBase:
+class Map:
def __init__(self, size=(0, 0)):
self.size = size
self.terrain = '?'*self.size_i
+ def __getitem__(self, yx):
+ return self.terrain[self.get_position_index(yx)]
+
+ def __setitem__(self, yx, c):
+ pos_i = self.get_position_index(yx)
+ if type(c) == str:
+ self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:]
+ else:
+ self.terrain[pos_i] = c
+
+ def __iter__(self):
+ """Iterate over YX position coordinates."""
+ for y in range(self.size[0]):
+ for x in range(self.size[1]):
+ yield (y, x)
+
@property
def size_i(self):
return self.size[0] * self.size[1]
def get_position_index(self, yx):
return yx[0] * self.size[1] + yx[1]
-
-class Map(MapBase):
-
- def __getitem__(self, yx):
- return self.terrain[self.get_position_index(yx)]
-
- def __setitem__(self, yx, c):
- pos_i = self.get_position_index(yx)
- if type(c) == str:
- self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:]
- else:
- self.terrain[pos_i] = c
-
- def __iter__(self):
- """Iterate over YX position coordinates."""
- for y in range(self.size[0]):
- for x in range(self.size[1]):
- yield (y, x)
-
def lines(self):
width = self.size[1]
for y in range(self.size[0]):
return self.neighbors_to[pos]
for direction in self.get_directions():
neighbors[direction] = None
- try:
- neighbors[direction] = self.move(pos, direction)
- except GameError:
- pass
+ neighbor_pos = self.move(pos, direction)
+ if neighbor_pos:
+ neighbors[direction] = neighbor_pos
self.neighbors_to[pos] = neighbors
return neighbors
new_pos = mover(start_pos)
if new_pos[0] < 0 or new_pos[1] < 0 or \
new_pos[0] >= self.size[0] or new_pos[1] >= self.size[1]:
- raise GameError('would move outside map bounds')
+ return None
return new_pos