blob: d80a4c918b2c1073e1d57a1e8aac449f04358e43 (
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
|
#include "gameplay.hpp"
#include "puzzle.hpp"
#include "FL/Fl_Group.H"
static bool is_next_to_empty_box(GameParams::coordinates empty_box_pos,
GameParams::coordinates current_pos)
{
return
(current_pos.x - spacing - puzzle_size == empty_box_pos.x &&
current_pos.y == empty_box_pos.y) ||
(current_pos.x == empty_box_pos.x &&
current_pos.y - spacing - puzzle_size == empty_box_pos.y) ||
(current_pos.x + puzzle_size + spacing == empty_box_pos.x &&
current_pos.y == empty_box_pos.y) ||
(current_pos.x == empty_box_pos.x &&
current_pos.y + puzzle_size + spacing == empty_box_pos.y);
}
void press_button_callback(Fl_Widget *w, void *params)
{
GameParams *gp = reinterpret_cast<GameParams*>(params);
GameParams::coordinates current_pos = { w->x(), w->y() };
if(is_next_to_empty_box(gp->GetXYEmptyBox(), current_pos)) {
w->position(gp->GetXYEmptyBox().x, gp->GetXYEmptyBox().y);
gp->SetXYEmptyBox(current_pos.x, current_pos.y);
}
w->redraw();
w->parent()->redraw();
}
|