[gnome-klotski] Improve a bit tile drop.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-klotski] Improve a bit tile drop.
- Date: Mon, 10 Feb 2020 17:18:45 +0000 (UTC)
commit aa8e19bb556981c8e54471beed1dcbb4cd06ea71
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Feb 9 05:20:24 2020 +0100
Improve a bit tile drop.
src/puzzle-view.vala | 6 +++++-
src/puzzle.vala | 11 +++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 706f29b..80bbc63 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -248,8 +248,12 @@ private class PuzzleView : Gtk.DrawingArea
if (Puzzle.is_static_tile (new_piece_id) || new_piece_id == piece_id)
return false;
- if (already_moving) // TODO skip the new piece selection if it cannot be moved
+ if (already_moving)
+ {
validate_move ();
+ if (!puzzle.can_be_moved (new_piece_id))
+ return false;
+ }
piece_unmoved = true;
piece_id = new_piece_id;
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 45e4f18..82694b2 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -287,6 +287,17 @@ private class Puzzle : Object
return return_value;
}
+ internal bool can_be_moved (int id)
+ {
+ if (is_static_tile (id))
+ return false;
+
+ return check_valid_move (id, 0, 1)
+ || check_valid_move (id, 0, -1)
+ || check_valid_move (id, 1, 0)
+ || check_valid_move (id, -1, 0);
+ }
+
private bool check_valid_move (int id, int dx, int dy)
{
for (var y = 0; y < height; y++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]