From e64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf Mon Sep 17 00:00:00 2001 From: scratko Date: Sat, 9 Nov 2024 20:00:19 +0300 Subject: Moving slides Changed to 8 puzzles Added reaction to clicking a puzzle Puzzles are moved to vector --- gameplay.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 gameplay.cpp (limited to 'gameplay.cpp') 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(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(); +} + -- cgit v1.2.3