back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/gameplay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gameplay.cpp')
-rw-r--r--gameplay.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/gameplay.cpp b/gameplay.cpp
new file mode 100644
index 0000000..d80a4c9
--- /dev/null
+++ b/gameplay.cpp
@@ -0,0 +1,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();
+}
+