#ifndef PUZZLE_HPP_SENTRY #define PUZZLE_HPP_SENTRY #include #include #include #include #include #include #include enum { puzzle_pieces = 9, // including empty puzzle puzzles_per_side = 3, puzzle_size = 100, spacing = 5 }; class Puzzle : public Fl_Button{ private: unsigned char sequence_number{}; // Path for file access error handling (ERR_FILE_ACCESS) std::string path; Fl_PNG_Image *stored_img_pointer; public: Puzzle(int x, int y) : Fl_Button(x, y, puzzle_size, puzzle_size), stored_img_pointer(nullptr) { } ~Puzzle() { delete stored_img_pointer; } friend class GameParams; friend class PuzzleGame; friend class ASearch; }; class GameParams { public: struct coordinates { int x, y; bool operator==(const coordinates& v) const { return this->x == v.x && this->y == v.y; } }; private: static GameParams *instance; coordinates standard_puzzle_coordinates[puzzle_pieces]; char free_puzzles[puzzle_pieces]; coordinates empty_box; std::vector> puzzles; Fl_Window *win; // True while A* is solving the puzzle; blocks new game and solving again bool is_a_star_active = false; // selecting the current directory where the user image is stored std::string cur_directory; GameParams(Fl_Window *a_win = nullptr) : win(a_win) {} void CalculateStandardPuzzlePos(); void ResetFreePuzzles(); void ResetAStarActive() { is_a_star_active = false; } void SetAStarActive() { is_a_star_active = true; } void NextUntestedPuzzles(); bool IsSolvability(); void CreateNewPuzzles(); void SelectRandomPicture(); Fl_PNG_Image *LoadPictureParts(std::unique_ptr& tmp_puzzle); void SetXYEmptyBox(int x, int y) { empty_box.x = x; empty_box. y = y; } coordinates GetXYEmptyBox() { return empty_box; } public: bool GetAStarActive() { return is_a_star_active; } static GameParams *SetUpParams(Fl_Window *win) { if(instance) return instance; GameParams *gi = new GameParams(win); gi->CalculateStandardPuzzlePos(); return gi; } friend class PuzzleGame; friend class ASearch; friend void press_button_callback(Fl_Widget*, void*); friend void solve_problem_callback(Fl_Widget*, void*); }; #endif