diff options
Diffstat (limited to 'puzzle.cpp')
-rw-r--r-- | puzzle.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -4,13 +4,15 @@ #include <algorithm> #include <stdlib.h> #include <string> +#include <string.h> +#include <FL/Fl.H> #include <FL/Fl_PNG_Image.H> +#include <FL/fl_ask.H> #include <utility> #include <memory> #include <filesystem> #include <random> - GameParams* GameParams::instance = nullptr; void GameParams::CalculateStandardPuzzlePos() @@ -47,8 +49,10 @@ void GameParams::NextUntestedPuzzles() /* * check if puzzles already were created */ - if(puzzles.size() != 0) + if(puzzles.size() != 0) { puzzles.clear(); + Fl::do_widget_deletion(); + } /* * ======== creating puzzles =========== */ @@ -74,13 +78,33 @@ void GameParams::NextUntestedPuzzles() find_path_to_picture(tmp_puzzle->path, cur_directory, tmp_puzzle->sequence_number); Fl_PNG_Image *img = new Fl_PNG_Image(tmp_puzzle->path.c_str()); - // TODO check fails img->fail(); + switch (img->fail()) { + case Fl_Image::ERR_NO_IMAGE: + case Fl_Image::ERR_FILE_ACCESS: + fl_alert("%s: %s", tmp_puzzle->path.c_str(), strerror(errno)); + exit(1); + case Fl_Image::ERR_FORMAT: + fl_alert("couldn't decode image"); + exit(1); + } tmp_puzzle->image(img); + tmp_puzzle->stored_img_pointer = img; tmp_puzzle->callback(press_button_callback, this); puzzles.push_back(std::move(tmp_puzzle)); } - win->end(); ResetFreePuzzles(); + /* + * Checking image shuffling + */ + bool shuffled_img = false; + for(int i = 0; i < puzzle_pieces-1; ++i) + if(puzzles[i]->sequence_number != i) { + shuffled_img = true; + break; + } + if(!shuffled_img) + NextUntestedPuzzles(); + win->end(); } bool GameParams::IsSolvability() |