69 lines
1.8 KiB
Python
Raw Permalink Normal View History

2022-10-17 19:17:22 +02:00
# Import 1st party modules
import curses
# Import my own libraries
from state import State
gamestate = State()
gamestate.load()
#print(gamestate.terrain[1][2])
def draw_map(stdscr):
# key press
k = 0
# Map center
center = {}
center['x'] = round(gamestate.metadata['width']/2)
center['y'] = round(gamestate.metadata['height']/2)
# Clear and refresh the screen for a blank canvas
stdscr.clear()
stdscr.refresh()
# Start colors in curses
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN) # Neutral Land
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # Neutral Sea
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_GREEN) # Friendly Land
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLUE) # Friendly Sea
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_GREEN) # Enemy Land
curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLUE) # Enemy Sea
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_BLACK) # Outside of the map
while (k != ord('q')):
# Initialization
stdscr.clear()
height, width = stdscr.getmaxyx()
if k == curses.KEY_DOWN:
center['y'] = center['y'] + 1
elif k == curses.KEY_UP:
center['y'] = center['y'] - 1
elif k == curses.KEY_RIGHT:
center['x'] = center['x'] + 1
elif k == curses.KEY_LEFT:
center['x'] = center['x'] - 1
for y in range(1,height):
for x in range(1,width):
if gamestate.terrain[x][y] == "l":
stdscr.addstr( y, x, " ", curses.color_pair(1) )
elif gamestate.terrain[x][y] == "w":
stdscr.addstr( y, x, " ", curses.color_pair(2) )
# Refresh the screen
stdscr.refresh()
# Wait for next input
k = stdscr.getch()
def main():
curses.wrapper(draw_map)
if __name__ == "__main__":
main()