blob: e44efd47e1eea99b39a9733a5c60a0a11484b5f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef PUZZLE_HPP_SENTRY
#define PUZZLE_HPP_SENTRY
#include <FL/Enumerations.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
#include <string>
#include <vector>
#include <memory>
enum {
puzzle_pieces = 9,
puzzles_per_side = 3,
puzzle_size = 100,
spacing = 5
};
class Puzzle : public Fl_Button{
public:
unsigned char sequence_number;
std::string path;
Puzzle(int x, int y)
: Fl_Button(x, y, puzzle_size, puzzle_size) {}
};
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<std::unique_ptr<Puzzle>> puzzles;
Fl_Window *win;
std::string cur_directory;
GameParams(Fl_Window *a_win = nullptr) : win(a_win) {}
void CalculateStandardPuzzlePos();
void ResetFreePuzzles();
void NextUntestedPuzzles();
bool IsSolvability();
void CreateNewPuzzles();
void SelectRandomPicture();
friend class PuzzleGame;
friend class ASearch;
friend void press_button_callback(Fl_Widget*, void*);
friend void solve_problem_callback(Fl_Widget*, void*);
public:
void SetXYEmptyBox(int x, int y) { empty_box.x = x; empty_box. y = y; }
coordinates GetXYEmptyBox() { return empty_box; }
static GameParams *SetUpParams(Fl_Window *win) {
if(instance)
return instance;
GameParams *gi = new GameParams(win);
gi->CalculateStandardPuzzlePos();
return gi;
}
};
#endif
|