From 0cb79422297e950242a4965cbe0d585214bdea76 Mon Sep 17 00:00:00 2001 From: otahina Date: Sun, 16 Jul 2023 20:43:54 +0900 Subject: [PATCH] make it user interactive --- projects/BFS visualizer/main.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/projects/BFS visualizer/main.py b/projects/BFS visualizer/main.py index f14c3bd7..2343a2cf 100644 --- a/projects/BFS visualizer/main.py +++ b/projects/BFS visualizer/main.py @@ -106,11 +106,32 @@ def start_location(maze_1, start): def main(stdscr): - curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + while True: + curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - find_path(maze_1, stdscr) - stdscr.getch() + # Print a message and wait for the user to press a key before starting + stdscr.addstr("Press any key to start...") + stdscr.getch() + stdscr.clear() + + # Call find_path and get the result + path = find_path(maze_1, stdscr) + + # Check if a path was found and print a message + if path is None: + stdscr.addstr("No path was found.\n") + else: + stdscr.addstr("A path was found!\n") + + # Print a message and wait for the user to press a key before continuing + stdscr.addstr("Press any key to continue or 'q' to quit...") + ch = stdscr.getch() + + # If the user pressed 'q', break out of the loop and end the program + if ch == ord('q'): + break + stdscr.clear() wrapper(main)