[gnome-klotski] Fix another bug.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-klotski] Fix another bug.
- Date: Sat, 8 Feb 2020 19:28:54 +0000 (UTC)
commit ac9a22b92f4e8a2b7d87a3df4c2795d6b1a57441
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Feb 8 20:26:49 2020 +0100
Fix another bug.
Closes #4.
src/puzzle-view.vala | 51 ++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
---
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 45bb9fa..fd9e004 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -243,6 +243,9 @@ private class PuzzleView : Gtk.DrawingArea
|| new_piece_id == '#' || new_piece_id == piece_id)
return false;
+ if (piece_id != '\0')
+ validate_move ();
+
piece_unmoved = true;
piece_id = new_piece_id;
puzzle.move_map = puzzle.map;
@@ -254,35 +257,37 @@ private class PuzzleView : Gtk.DrawingArea
protected override bool button_release_event (Gdk.EventButton event)
{
if (event.button == Gdk.BUTTON_PRIMARY && piece_id != '\0')
- {
- if (piece_unmoved)
- return false;
+ validate_move ();
+
+ return false;
+ }
+ private void validate_move ()
+ {
+ if (piece_unmoved)
+ return;
- if (puzzle.movable (piece_id) && puzzle.mapcmp (puzzle.move_map, puzzle.map))
+ if (puzzle.movable (piece_id) && puzzle.mapcmp (puzzle.move_map, puzzle.map))
+ {
+ if (last_piece_id == '\0' || last_piece_id != piece_id)
{
- if (last_piece_id == '\0' || last_piece_id != piece_id)
- {
- puzzle.undomove_map = puzzle.lastmove_map;
- if (puzzle.moves < 10000 /* or up to uint16.MAX */)
- puzzle.moves++;
- }
+ puzzle.undomove_map = puzzle.lastmove_map;
+ if (puzzle.moves < 10000 /* or up to uint16.MAX */)
+ puzzle.moves++;
+ }
- if (puzzle.moves > 0 && !puzzle.mapcmp (puzzle.undomove_map, puzzle.map))
- {
- puzzle.moves--;
- last_piece_id = '\0';
- }
- else
- last_piece_id = piece_id;
+ if (puzzle.moves > 0 && !puzzle.mapcmp (puzzle.undomove_map, puzzle.map))
+ {
+ puzzle.moves--;
+ last_piece_id = '\0';
+ }
+ else
+ last_piece_id = piece_id;
- puzzle.lastmove_map = puzzle.map;
+ puzzle.lastmove_map = puzzle.map;
- puzzle.moved ();
- }
- piece_id = '\0';
+ puzzle.moved ();
}
-
- return false;
+ piece_id = '\0';
}
protected override bool motion_notify_event (Gdk.EventMotion event)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]