def dummy_root(dim=Dim(120, 40), border=0, logger=Logger('stderr')): dcurses = DummyCurses(dim) return RootLayout(dim=dim, border=border, logger=logger, scr=dcurses.term, curses=dcurses)
def __init__(self, parent, pos, dim): self.parent = parent self.pos = Pos(pos.x, pos.y) self.con = None if parent: self.buf = parent.buf self.dim = Dim(dim.w, dim.h) else: self.resize(dim.h, dim.w)
def assert_game(model, keys, paint=False): root_layout = dummy_root(dim=Dim(110, 14), logger=Logger('dbg.py')) control = PrpgControl(root_layout, model) def get_key(): if paint: control.root_layout.window.paint() ret = keys.pop(0) return ret main(root_layout, model, get_key=get_key)
def cb(scr): root_layout = RootLayout(dim=Dim(w, h), border=0, logger=Logger(__file__), scr=scr, curses=curses) game = GameModel(create_peep('human', name='Super Dad')) game.player.body.wear(clothes.cloak(size=Size(1.1, 1.1, 1.1), thick=1.0)) game.player.body.wear(armor.helm(size=Size(1.15, 1.1, 1.1), thick=1.0)) # game.player.body.wear(armor.shield(size=Size(1.4, 1.1, 1.0), thick=1.1)) game.player.body.wear(weapons.sword(size=Size(1.0, 1.0, 1.0))) game.goto_level(1, placement='<') main(root_layout, game)
def test_draw_target(): data = ( (0, -4), (1, -4), (2, -4), (3, -4), (4, -4), (4, -3), (4, -2), (4, -1), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (3, 4), (2, 4), (1, 4), (0, 4), (-1, 4), (-2, 4), (-3, 4), (-4, 4), (-4, 3), (-4, 2), (-4, 1), (-4, 0), (-4, -1), (-4, -2), (-4, -3), (-4, -4), (-3, -4), (-2, -4), (-1, -4), (0, -4), ) random.seed = 1 game = dungeons.create_game({ 'walls': [ '%%%%%%%%%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%%%%%%%%%', ], 'peeps': [ create_peep('human', name='Super Dad', pos=(4, 4)), ] }) root_layout = dummy_root(dim=Dim(11, 11), logger=Logger('dbg.py')) control = PrpgControl(root_layout, game) for comp in root_layout.info.comp_by_name.values(): if not comp.children and comp.name != 'maze': comp.con = Con(0, 0, 1, 1) root_layout.do_layout() player = game.maze_model.peeps[0] for target in data: tp = (player.pos[0] + target[0], player.pos[1] + target[1]) game.maze_model.target_path = tuple(line_points(player.pos, tp)) control.root_layout.window.paint()
def derwin(self, h, w, y, x): return DummyCursesWindow(self, Pos(x, y), Dim(w, h))
def resize(self, h, w): if self.parent: raise ValueError("resize() supported only for root") self.dim = Dim(w, h) self.buf = [x[:] for x in [['.'] * self.dim.w] * self.dim.h]