[gnome-nibbles/arnaudb/modernize-code: 20/58] Move more bonuses management in Boni.



commit d64bcea5c3cc32374a86b5a1e9978fabe0fbfa82
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 27 14:39:20 2020 +0200

    Move more bonuses management in Boni.

 src/boni.vala         | 28 +++++++++++++++++++++++++++-
 src/nibbles-game.vala | 29 ++++++-----------------------
 2 files changed, 33 insertions(+), 24 deletions(-)
---
diff --git a/src/boni.vala b/src/boni.vala
index e4e9d7e..4e3459a 100644
--- a/src/boni.vala
+++ b/src/boni.vala
@@ -106,6 +106,32 @@ private class Boni : Object
         return null;
     }
 
+    internal void on_worms_move (int[,] board, out uint8 missed_bonuses_to_replace)
+    {
+        missed_bonuses_to_replace = 0;
+
+        // FIXME Use an iterator instead of a second list and
+        // remove from the bonuses list inside remove_bonus()
+        var found = new Gee.LinkedList<Bonus> ();
+        foreach (var bonus in bonuses)
+        {
+            if (bonus.countdown-- == 0)
+            {
+                bool missed = bonus.bonus_type == BonusType.REGULAR && !bonus.fake;
+
+                found.add (bonus);
+                remove_bonus (board, bonus);
+
+                if (missed)
+                {
+                    increase_missed ();
+                    missed_bonuses_to_replace++;
+                }
+            }
+        }
+        bonuses.remove_all (found);
+    }
+
     /*\
     * * missed
     \*/
@@ -118,7 +144,7 @@ private class Boni : Object
         return missed > MAX_MISSED;
     }
 
-    internal inline void increase_missed ()
+    private inline void increase_missed ()
     {
         missed++;
     }
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 513ee47..ed078d9 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -234,27 +234,10 @@ private class NibblesGame : Object
             }
         }
 
-        // FIXME 1/3: Use an iterator instead of a second list and remove
-        // from the boni.bonuses list inside boni.remove_bonus ()
-        var found = new Gee.LinkedList<Bonus> ();
-        foreach (var bonus in boni.bonuses)
-        {
-            if (bonus.countdown-- == 0)
-            {
-                bool missed = bonus.bonus_type == BonusType.REGULAR && !bonus.fake;
-
-                found.add (bonus);
-                boni.remove_bonus (board, bonus);
-
-                if (missed)
-                {
-                    boni.increase_missed ();
-                    add_bonus (true);
-                }
-            }
-        }
-        boni.bonuses.remove_all (found);
-        // END FIXME
+        uint8 missed_bonuses_to_replace;
+        boni.on_worms_move (board, out missed_bonuses_to_replace);
+        for (uint8 i = 0; i < missed_bonuses_to_replace; i++)
+            add_bonus (true);
 
         var dead_worms = new Gee.LinkedList<Worm> ();
         foreach (var worm in worms)
@@ -463,7 +446,7 @@ private class NibblesGame : Object
         if (board[worm.head.x, worm.head.y] == BonusType.REGULAR + 'A'
             && !bonus.fake)
         {
-            // FIXME: 2/3
+            // FIXME: see Boni.on_worms_move()
             boni.remove_bonus (board, bonus);
             boni.bonuses.remove (bonus);
 
@@ -472,7 +455,7 @@ private class NibblesGame : Object
         }
         else
         {
-            // FIXME: 3/3
+            // FIXME: see Boni.on_worms_move()
             boni.remove_bonus (board, bonus);
             boni.bonuses.remove (bonus);
         }


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