[gnome-nibbles] Fix duplicated player boxes when starting a new game



commit 769b779f6446138f56f335a20a233252535c4a89
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Tue Aug 11 12:22:32 2015 +0300

    Fix duplicated player boxes when starting a new game

 src/gnome-nibbles.vala |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index a7151b5..f3a1faa 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -261,6 +261,7 @@ public class Nibbles : Gtk.Application
         view.new_level (game.current_level);
         view.connect_worm_signals ();
 
+        scoreboard.clear ();
         foreach (var worm in game.worms)
         {
             var color = game.worm_props.get (worm).color;
@@ -594,7 +595,7 @@ public class Scoreboard : Gtk.Box
         var color = Pango.Color ();
         color.parse (color_name);
 
-        var box = new PlayerScoreBox ("Worm %d".printf (worm.id + 1), color, worm.score, worm.lives, 
life_pixbuf);
+        var box = new PlayerScoreBox (@"Worm $(worm.id + 1)", color, worm.score, worm.lives, life_pixbuf);
         boxes.set (box, worm);
         add (box);
     }
@@ -603,8 +604,21 @@ public class Scoreboard : Gtk.Box
     {
         foreach (var entry in boxes.entries)
         {
-            entry.key.update (entry.value.score, entry.value.lives);
+            var box = entry.key;
+            var worm = entry.value;
+
+            box.update (worm.score, worm.lives);
+        }
+    }
+
+    public void clear ()
+    {
+        foreach (var entry in boxes.entries)
+        {
+            var box = entry.key;
+            box.destroy ();
         }
+        boxes.clear ();
     }
 }
 


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