Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- world_config = '''
- ######
- ##########
- ####### 000000...
- !!!!!***** qqqqq0000000000.......
- !!!!*******qqqqqqqqqq 0000....
- %%%%% *******qqqqq
- %% zzzwwwwwwww
- % zzzzwwww
- zzzz
- zz
- z
- '''.split('\n')[1:-1]
- class World:
- def __init__(self, tiles, sea=' '):
- self._map = tiles
- self.provinces = set(''.join(tiles))
- self.provinces.remove(' ')
- self.height = len(tiles)
- self.width = max(map(len, tiles))
- def at(self, y, x):
- return self.provinces[y][x]
- @property
- def map(self): return self._map
- class Realm:
- def __init__(self, sym, idx=-1):
- self._sym = sym
- self._id = ord(sym) if idx < 0 else idx
- @property
- def id(self): return self._id
- @property
- def sym(self): return self._sym
- def main():
- scr = curses.initscr()
- w = curses.newwin(0, 0)
- world = World(world_config)
- input_key = None
- curx, cury = 0, 5
- status_bar_msg = ''
- def draw():
- w.move(0, 0)
- for y, l in enumerate(world.map):
- for x, c in enumerate(l):
- w.addch(c)
- w.move(y + 1, 0)
- def draw_hud():
- wmaxy, wmaxx = w.getmaxyx()
- hudy, hudx = wmaxy - 2, 0
- w.move(hudy - 1, hudx)
- w.addstr('─' * wmaxx)
- w.move(hudy + 1, hudx)
- w.addstr(f'{cury=};{curx=};{input_key=}')
- w.move(hudy, hudx + 2)
- w.addstr(status_bar_msg)
- draw()
- draw_hud()
- w.refresh()
- w.move(cury, curx)
- running = True
- while running:
- try:
- input_key = w.getkey()
- if input_key == 'h':
- curx -= 1
- elif input_key == 'l':
- curx += 1
- elif input_key == 'j':
- cury += 1
- elif input_key == 'k':
- cury -= 1
- elif input_key == 'q':
- running = False
- else:
- status_bar_msg = 'Неизвестная клавиша'
- draw()
- draw_hud()
- w.refresh()
- except KeyboardInterrupt:
- running = False
- curses.endwin()
- if __name__ == '__main__':
- try:
- main()
- except:
- curses.endwin()
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement