squirrel-battle/dungeonbattle/proof_of_concept.py

37 lines
1.2 KiB
Python
Raw Normal View History

2020-10-16 13:23:58 +00:00
#!/usr/bin/env python
2020-10-16 14:46:40 +00:00
from .interfaces import Map
2020-10-16 13:23:58 +00:00
from .term_manager import TermManager
def proof_of_concept() -> None:
2020-10-16 14:46:40 +00:00
m = Map.load("example_map.txt")
2020-10-16 13:23:58 +00:00
with TermManager() as term_manager:
stdscr = term_manager.screen
2020-10-16 14:46:40 +00:00
stdscr.addstr(0, 0, m.draw_string())
2020-10-16 13:23:58 +00:00
stdscr.refresh()
cur = [1, 6] # (y,x)
stdscr.addstr(1, 6, '@')
stdscr.refresh()
while True:
key = stdscr.getkey()
stdscr.addstr(cur[0], cur[1], '.')
2020-10-16 13:32:15 +00:00
if key == 'z' or key == 'KEY_UP':
2020-10-16 14:46:40 +00:00
if cur[0] > 0 and m.tiles[cur[0] - 1][cur[1]].value != '#':
2020-10-16 13:23:58 +00:00
cur[0] = cur[0] - 1
2020-10-16 13:32:15 +00:00
if key == 's' or key == 'KEY_DOWN':
2020-10-16 14:46:40 +00:00
if cur[0] < m.height - 1 and \
m.tiles[cur[0] + 1][cur[1]].value != '#':
2020-10-16 13:23:58 +00:00
cur[0] = cur[0] + 1
2020-10-16 13:32:15 +00:00
if key == 'q' or key == 'KEY_LEFT':
2020-10-16 14:46:40 +00:00
if cur[1] > 0 and m.tiles[cur[0]][cur[1] - 1].value != '#':
2020-10-16 13:23:58 +00:00
cur[1] = cur[1] - 1
2020-10-16 13:32:15 +00:00
if key == 'd' or key == 'KEY_RIGHT':
2020-10-16 14:46:40 +00:00
if cur[1] < m.width and \
m.tiles[cur[0]][cur[1] + 1].value != '#':
2020-10-16 13:23:58 +00:00
cur[1] = cur[1] + 1
stdscr.addstr(cur[0], cur[1], '@')