#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(); }