[gnome-nibbles] Replace bonus when countdown reaches 0.



commit f3faba2a5fe0c757c3e1f1d1acaf1d2d1dde9f5a
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Fri Jul 3 17:03:58 2015 +0300

    Replace bonus when countdown reaches 0.

 src/boni.vala         |   12 ++++++++++++
 src/nibbles-game.vala |   20 ++++++++++++++++++++
 src/nibbles-view.vala |    8 ++++++++
 src/worm.vala         |    3 +++
 4 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/boni.vala b/src/boni.vala
index 2f5462f..a76df64 100644
--- a/src/boni.vala
+++ b/src/boni.vala
@@ -28,6 +28,7 @@ public class Boni : Object
     public const int MAX_MISSED = 2;
 
     public signal void bonus_added ();
+    public signal void bonus_removed (Bonus bonus);
 
     public Boni (int numworms)
     {
@@ -55,6 +56,17 @@ public class Boni : Object
         // if (type != BonusType.REGULAR)
         //     play_sound ("appear");
     }
+
+    public void remove_bonus (int[,] walls, Bonus bonus)
+    {
+        walls[bonus.x, bonus.y] = NibblesGame.EMPTYCHAR;
+        walls[bonus.x + 1, bonus.y] = NibblesGame.EMPTYCHAR;
+        walls[bonus.x, bonus.y + 1] = NibblesGame.EMPTYCHAR;
+        walls[bonus.x + 1, bonus.y + 1] = NibblesGame.EMPTYCHAR;
+
+        bonuses.remove (bonus);
+        bonus_removed (bonus);
+    }
 }
 
 public class Bonus : Object
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 3282969..a64b661 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -199,6 +199,26 @@ public class NibblesGame : Object
     {
         foreach (var worm in worms)
         {
+            if (boni.missed > Boni.MAX_MISSED)
+            {
+                if (worm.score > 0)
+                    worm.score--;
+            }
+
+            foreach (var bonus in boni.bonuses)
+            {
+                if (bonus.countdown-- == 0)
+                {
+                    if (bonus.type == BonusType.REGULAR && !bonus.fake)
+                    {
+                        boni.remove_bonus (walls, bonus);
+                        boni.missed++;
+                        add_bonus (true);
+                    }
+                    else
+                        boni.remove_bonus (walls, bonus);
+                }
+            }
             if (worm.is_stopped)
                 continue;
 
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 1319b4d..c7c3797 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -30,6 +30,7 @@ public class NibblesView : GtkClutter.Embed
 
             _game = value;
             _game.boni.bonus_added.connect (bonus_added_cb);
+            _game.boni.bonus_removed.connect (bonus_removed_cb);
         }
     }
 
@@ -541,6 +542,13 @@ public class NibblesView : GtkClutter.Embed
         bonus_actors.set (bonus, actor);
     }
 
+    public void bonus_removed_cb (Bonus bonus)
+    {
+        var bonus_actor = bonus_actors.get (bonus);
+        bonus_actor.hide ();
+        stage.remove_child (bonus_actor);
+    }
+
     public void boni_rescale (int tile_size)
     {
         float x_pos, y_pos;
diff --git a/src/worm.vala b/src/worm.vala
index b760437..8754c60 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -33,6 +33,8 @@ public class Worm : Object
     public bool is_stopped = false;
 
     public int lives { get; private set; }
+    public int score;
+
     private WormDirection _direction;
     public WormDirection direction
     {
@@ -67,6 +69,7 @@ public class Worm : Object
         human = true;
         starting_direction = direction;
         lives = STARTING_LIVES;
+        score = 0;
         list = new Gee.LinkedList<Position?> ();
         key_queue = new Gee.ArrayQueue<WormDirection> ();
     }


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