back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/puzzle.hpp
blob: 5b2b2ab3816a6cc728874e0d7aca384d2178191e (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
#ifndef PUZZLE_HPP_SENTRY
#define PUZZLE_HPP_SENTRY

#include <FL/Enumerations.H>
#include <FL/Fl_Button.H>
#include <string>
#include <vector>
#include <memory>

enum {
    puzzle_pieces       = 8,
    puzzles_per_side    = 3,
    puzzle_size         = 100,
    spacing             = 5
};

class Puzzle : Fl_Button{
    unsigned char sequence_number;
    std::string path;
    Puzzle(int x, int y)
        : Fl_Button(x, y, puzzle_size, puzzle_size) {}
    friend class GameParams;
};

class GameParams {
public:
    struct coordinates {
        int x, y;
    };
private:
    coordinates standard_puzzle_coordinates[puzzle_pieces];
    char free_puzzles[puzzle_pieces];
    coordinates empty_box;
    std::vector<std::unique_ptr<Puzzle>> puzzles;

    GameParams() {}
    void CalculateStandardPuzzlePos();
    void ResetFreePuzzles();
    void CreateNewPuzzles();
public:
    void NewGame();
    void SetXYEmptyBox(int x, int y) { empty_box.x = x; empty_box. y = y; }
    coordinates GetXYEmptyBox() { return empty_box; }
    static GameParams *SetUpParams() {
        GameParams *gi = new GameParams;
        gi->CalculateStandardPuzzlePos();
        return gi;
    }
};

#endif