[gnome-2048] Undo score change with undo move (bgo#756758)



commit af697a369bf54f240628e9a1c9d4dc8e4aa690ce
Author: Robert Roth <robert roth off gmail com>
Date:   Sat Dec 26 23:12:33 2015 +0200

    Undo score change with undo move (bgo#756758)

 src/game.vala |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index f18e6e3..cc2aeac 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -55,6 +55,7 @@ public class Game : GLib.Object
   private bool _allow_undo;
   private uint _undo_stack_max_size;
   private Gee.LinkedList<Grid> _undo_stack;
+  private Gee.LinkedList<uint> _undo_score_stack;
 
   private GLib.Settings _settings;
 
@@ -91,6 +92,7 @@ public class Game : GLib.Object
     _view_foreground.show ();
 
     _undo_stack = new Gee.LinkedList<Grid> ();
+    _undo_score_stack = new Gee.LinkedList<uint> ();
     _allow_undo = _settings.get_boolean ("allow-undo");
     _undo_stack_max_size = _settings.get_int ("allow-undo-max");
 
@@ -119,6 +121,7 @@ public class Game : GLib.Object
       Source.remove (_finish_move_id);
     _grid.clear ();
     _undo_stack.clear ();
+    _undo_score_stack.clear ();
     // new_game could be called without an existing game
     if (_background == null)
       _init_background ();
@@ -133,9 +136,12 @@ public class Game : GLib.Object
   public void undo ()
   {
     Grid grid = _undo_stack.poll_head ();
+    uint delta_score = _undo_score_stack.poll_head ();
+
     _clear_foreground ();
     _grid = grid;
     _restore_foreground (false);
+    score -= delta_score;
 
     if (_undo_stack.size == 0)
       undo_disabled ();
@@ -216,6 +222,7 @@ public class Game : GLib.Object
     allow_undo = _settings.get_boolean ("allow-undo");
     if (_allow_undo && !allow_undo) {
       _undo_stack.clear ();
+      _undo_score_stack.clear ();
       undo_disabled ();
     }
     _allow_undo = allow_undo;
@@ -649,6 +656,7 @@ public class Game : GLib.Object
       delta_score += e.val;
     }
     score += delta_score;
+    _store_score_update (delta_score);
 
     _create_random_tile ();
 
@@ -738,4 +746,13 @@ public class Game : GLib.Object
       }
     }
   }
+
+  private void _store_score_update (uint delta_score)
+  {
+    if (_allow_undo) {
+      if (_undo_score_stack.size == _undo_stack_max_size)
+        _undo_score_stack.poll_tail ();
+      _undo_score_stack.offer_head (delta_score);
+    }
+  }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]