From ef6e5d66ca4a3142c7127c6a4b76a3a2ab41c9c0 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 16 Oct 2020 15:23:58 +0200 Subject: [PATCH] Cleaner proof of concept --- dungeonbattle/player_move_essai2.py | 44 ------------------------ dungeonbattle/proof_of_concept.py | 40 +++++++++++++++++++++ dungeonbattle/map.txt => example_map.txt | 0 main.py | 3 +- 4 files changed, 42 insertions(+), 45 deletions(-) delete mode 100644 dungeonbattle/player_move_essai2.py create mode 100644 dungeonbattle/proof_of_concept.py rename dungeonbattle/map.txt => example_map.txt (100%) mode change 100644 => 100755 main.py diff --git a/dungeonbattle/player_move_essai2.py b/dungeonbattle/player_move_essai2.py deleted file mode 100644 index ea44442..0000000 --- a/dungeonbattle/player_move_essai2.py +++ /dev/null @@ -1,44 +0,0 @@ -import curses -from term_manager import TermManager -import time - -filename = "map.txt" -A = open(filename) -M = [] - -i = 0 -for lines in A : - B = list(lines)[:-1] - M.append(B) - i+=1 -print(M) - -def main(stdscr): - for y in range(len(M)): #len(M) - for x in range(len(M[0])): #len(M[0]) - stdscr.addstr(y,x,M[y][x]) - stdscr.refresh() - - cur = [1,6] #(y,x) - stdscr.addstr(1,6,'@') - stdscr.refresh() - - for i in range(10) : - key = stdscr.getkey() - stdscr.addstr(cur[0],cur[1],'.') - if key == 'z' : - if cur[0]>0 and M[cur[0]-1][cur[1]] != '#' : - cur[0] = cur[0]-1 - if key == 's' : - if cur[0]0 and M[cur[0]][cur[1]-1] != '#' : - cur[1] = cur[1]-1 - if key == 'd' : - if cur[1] None: + matrix = [] + with open("example_map.txt") as f: + for line in f.readlines(): + matrix.append(line[:-1]) + + with TermManager() as term_manager: + stdscr = term_manager.screen + + for y in range(len(matrix)): + for x in range(len(matrix[0])): + stdscr.addstr(y, x, matrix[y][x]) + stdscr.refresh() + + cur = [1, 6] # (y,x) + stdscr.addstr(1, 6, '@') + stdscr.refresh() + + while True: + key = stdscr.getkey() + stdscr.addstr(cur[0], cur[1], '.') + if key == 'z': + if cur[0] > 0 and matrix[cur[0] - 1][cur[1]] != '#': + cur[0] = cur[0] - 1 + if key == 's': + if cur[0] < len(matrix) - 1 and \ + matrix[cur[0] + 1][cur[1]] != '#': + cur[0] = cur[0] + 1 + if key == 'q': + if cur[1] > 0 and matrix[cur[0]][cur[1] - 1] != '#': + cur[1] = cur[1] - 1 + if key == 'd': + if cur[1] < len(matrix[0]) and \ + matrix[cur[0]][cur[1] + 1] != '#': + cur[1] = cur[1] + 1 + stdscr.addstr(cur[0], cur[1], '@') diff --git a/dungeonbattle/map.txt b/example_map.txt similarity index 100% rename from dungeonbattle/map.txt rename to example_map.txt diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 1158de2..0eb26bf --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from dungeonbattle.proof_of_concept import proof_of_concept if __name__ == "__main__": - print("Hello world!") + proof_of_concept()