back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/gameplay.cpp
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-11-09 20:00:19 +0300
committerscratko <m@scratko.xyz>2024-11-09 20:12:48 +0300
commite64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf (patch)
tree5d42ff77afaeb101ff260ddf06b733cf0ef6fa61 /gameplay.cpp
parent365c27f05d5739213d3a98aa41dcc7f1cb0a6c60 (diff)
downloadpicture-puzzle-e64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf.tar.gz
picture-puzzle-e64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf.tar.bz2
picture-puzzle-e64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf.zip
Moving slides
Changed to 8 puzzles Added reaction to clicking a puzzle Puzzles are moved to vector
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();
+}
+