def main(stdscr): curses.curs_set(0) curses.start_color() curses.initscr() # Create windows for log (lines 1-3), map (lines 4-20) and stats (lines 21-24). log_window = curses.newwin(3, 79, 0, 1) map_window = curses.newwin(17, 79, 3, 1) stat_window = curses.newwin(4, 79, 20, 1) dungeon = Dungeon() dungeon.create_item(7, 9, "ring") dungeon.create_item(10, 12, "ring") dungeon.create_item(20, 10, "potion") player = Player() state = Basic(stdscr, log_window, map_window, stat_window, dungeon, player) new_state = None while 1: window_size = stdscr.getmaxyx() # Check if the terminal size is botched - refactor when you understand curses better if window_size[0] < 24 or window_size[1] < 80: state = create_state("termresize", stdscr, log_window, map_window, stat_window, dungeon, player) state.draw() curses.doupdate() c = stdscr.getch() else: # Cargoculted on Monday morning, 05:00. # Not doing this initscr() will result in a black screen before first keypress when moving # to a new state. No idea what causes this. Will do for now. if new_state is not None: curses.initscr() state.draw() curses.doupdate() c = stdscr.getch() new_state = state.handle_input(c) if new_state is not None: if new_state == "quit" : break else: state = create_state(new_state, stdscr, log_window, map_window, stat_window, dungeon, player) stdscr.erase()