diff options
author | scratko <m@scratko.xyz> | 2024-11-22 02:31:26 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-11-22 02:31:26 +0300 |
commit | ec2e197c9342b04cae6ef24cb293eabe57100dc8 (patch) | |
tree | e6e5dc3191d1bccbed1499c33a119feba199e412 | |
parent | 2f17165bd4c86885a75424d4f0ce6198c46c84b4 (diff) | |
download | picture-puzzle-ec2e197c9342b04cae6ef24cb293eabe57100dc8.tar.gz picture-puzzle-ec2e197c9342b04cae6ef24cb293eabe57100dc8.tar.bz2 picture-puzzle-ec2e197c9342b04cae6ef24cb293eabe57100dc8.zip |
Termination of the program while the computer is solving the algorithm
(by esc key)
-rw-r--r-- | main.cpp | 18 | ||||
-rw-r--r-- | solution_algorithm.cpp | 1 |
2 files changed, 18 insertions, 1 deletions
@@ -9,10 +9,26 @@ #include "gameplay.hpp" #include "menu_callbacks.hpp" +class MainWindow : public Fl_Window { +public: + MainWindow(int w, int h, const char *title) : Fl_Window(w, h, title) {} + /* + * Ending program by esc key while the computer is solving a puzzle + */ + int handle(int event) { + if(event == FL_KEYDOWN && Fl::event_length() != 0 && + Fl::event_key() == FL_Escape) + { + exit(0); + } + return Fl_Window::handle(event); + } +}; + int main() { srand(time(nullptr)); - Fl_Window *win = new Fl_Window(320, 355, "Picture puzzle"); + MainWindow *win = new MainWindow(320, 355, "Picture puzzle"); GameParams *params = GameParams::SetUpParams(win); Fl_Sys_Menu_Bar *sys_bar = new Fl_Sys_Menu_Bar(0, 0, 355, 20, nullptr); sys_bar->add("&File/&New game", nullptr, new_game_callback, params); diff --git a/solution_algorithm.cpp b/solution_algorithm.cpp index f0b7861..d96374b 100644 --- a/solution_algorithm.cpp +++ b/solution_algorithm.cpp @@ -178,6 +178,7 @@ void ASearch::ShowSolution(Node *goal) (*puzzle_pos)->position(goal->state[i].x, goal->state[i].y); gp->win->redraw(); Fl::flush(); + Fl::check(); usleep(40000); } } |