diff options
Diffstat (limited to 'puzzle.cpp')
-rw-r--r-- | puzzle.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -1,11 +1,15 @@ #include "puzzle.hpp" #include "gameplay.hpp" +#include <algorithm> #include <stdlib.h> #include <string> #include <FL/Fl_PNG_Image.H> #include <utility> #include <memory> +#include <filesystem> +#include <random> + GameParams* GameParams::instance = nullptr; @@ -28,10 +32,11 @@ void GameParams::ResetFreePuzzles() free_puzzles[i] = 1; } -static void find_path_to_picture(std::string& path, int number) +static void find_path_to_picture(std::string& path, + const std::string& cur_directory, int number) { path = - "resources/tucan/" + std::to_string(number / puzzles_per_side) + + cur_directory + std::to_string(number / puzzles_per_side) + std::to_string(number % puzzles_per_side) + ".png"; } @@ -66,7 +71,8 @@ void GameParams::NextUntestedPuzzles() std::unique_ptr<Puzzle>(new Puzzle(standard_puzzle_coordinates[i].x, standard_puzzle_coordinates[i].y)); tmp_puzzle->sequence_number = idx_random_puzzle; - find_path_to_picture(tmp_puzzle->path, tmp_puzzle->sequence_number); + 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(); tmp_puzzle->image(img); @@ -93,3 +99,20 @@ void GameParams::CreateNewPuzzles() NextUntestedPuzzles(); } while(!IsSolvability()); } + +void GameParams::SelectRandomPicture() +{ + std::vector<std::string> choices; + for (const auto& entry : std::filesystem::directory_iterator("resources")) { + choices.emplace_back(entry.path().string()); + } + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(choices.begin(), choices.end(), g); + cur_directory = choices[0]; +#if defined(_WIN32) + cur_directory.append("\\"); +#else + cur_directory.append("/"); +#endif +} |