Use Map interface in proof of concept
This commit is contained in:
parent
1054d8e57a
commit
cadc8c161e
|
@ -1,19 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
from .interfaces import Map
|
||||||
from .term_manager import TermManager
|
from .term_manager import TermManager
|
||||||
|
|
||||||
|
|
||||||
def proof_of_concept() -> None:
|
def proof_of_concept() -> None:
|
||||||
matrix = []
|
m = Map.load("example_map.txt")
|
||||||
with open("example_map.txt") as f:
|
|
||||||
for line in f.readlines():
|
|
||||||
matrix.append(line[:-1])
|
|
||||||
|
|
||||||
with TermManager() as term_manager:
|
with TermManager() as term_manager:
|
||||||
stdscr = term_manager.screen
|
stdscr = term_manager.screen
|
||||||
|
|
||||||
for y in range(len(matrix)):
|
stdscr.addstr(0, 0, m.draw_string())
|
||||||
for x in range(len(matrix[0])):
|
|
||||||
stdscr.addstr(y, x, matrix[y][x])
|
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
cur = [1, 6] # (y,x)
|
cur = [1, 6] # (y,x)
|
||||||
|
@ -24,17 +20,17 @@ def proof_of_concept() -> None:
|
||||||
key = stdscr.getkey()
|
key = stdscr.getkey()
|
||||||
stdscr.addstr(cur[0], cur[1], '.')
|
stdscr.addstr(cur[0], cur[1], '.')
|
||||||
if key == 'z' or key == 'KEY_UP':
|
if key == 'z' or key == 'KEY_UP':
|
||||||
if cur[0] > 0 and matrix[cur[0] - 1][cur[1]] != '#':
|
if cur[0] > 0 and m.tiles[cur[0] - 1][cur[1]].value != '#':
|
||||||
cur[0] = cur[0] - 1
|
cur[0] = cur[0] - 1
|
||||||
if key == 's' or key == 'KEY_DOWN':
|
if key == 's' or key == 'KEY_DOWN':
|
||||||
if cur[0] < len(matrix) - 1 and \
|
if cur[0] < m.height - 1 and \
|
||||||
matrix[cur[0] + 1][cur[1]] != '#':
|
m.tiles[cur[0] + 1][cur[1]].value != '#':
|
||||||
cur[0] = cur[0] + 1
|
cur[0] = cur[0] + 1
|
||||||
if key == 'q' or key == 'KEY_LEFT':
|
if key == 'q' or key == 'KEY_LEFT':
|
||||||
if cur[1] > 0 and matrix[cur[0]][cur[1] - 1] != '#':
|
if cur[1] > 0 and m.tiles[cur[0]][cur[1] - 1].value != '#':
|
||||||
cur[1] = cur[1] - 1
|
cur[1] = cur[1] - 1
|
||||||
if key == 'd' or key == 'KEY_RIGHT':
|
if key == 'd' or key == 'KEY_RIGHT':
|
||||||
if cur[1] < len(matrix[0]) and \
|
if cur[1] < m.width and \
|
||||||
matrix[cur[0]][cur[1] + 1] != '#':
|
m.tiles[cur[0]][cur[1] + 1].value != '#':
|
||||||
cur[1] = cur[1] + 1
|
cur[1] = cur[1] + 1
|
||||||
stdscr.addstr(cur[0], cur[1], '@')
|
stdscr.addstr(cur[0], cur[1], '@')
|
||||||
|
|
Loading…
Reference in New Issue