[gnome-nibbles] statusbar: fix lives boxes resizing all the time
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] statusbar: fix lives boxes resizing all the time
- Date: Mon, 26 Oct 2015 00:21:51 +0000 (UTC)
commit 015974f27d615e0879f9bde6ebda9f1b44541abe
Author: Iulian Radu <iulian radu67 gmail com>
Date: Thu Aug 20 19:49:43 2015 +0300
statusbar: fix lives boxes resizing all the time
data/player-score-box.ui | 2 --
src/gnome-nibbles.vala | 24 ++++++++----------------
src/nibbles-game.vala | 6 +++---
src/worm.vala | 14 ++++++++++++--
4 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/data/player-score-box.ui b/data/player-score-box.ui
index b33ee09..51f110a 100644
--- a/data/player-score-box.ui
+++ b/data/player-score-box.ui
@@ -3,8 +3,6 @@
<template class="PlayerScoreBox" parent="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="width-request">120</property>
- <property name="homogeneous">True</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index e6dd426..f393c82 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -848,13 +848,14 @@ private class PlayerScoreBox : Gtk.Box
life_images = new Gee.LinkedList<Gtk.Image> ();
- for (int i = 0; i < lives_left; i++)
+ for (int i = 0; i < Worm.MAX_LIVES; i++)
{
var life = new Gtk.Image.from_pixbuf (life_pixbuf);
- life.show ();
+ if (i < Worm.STARTING_LIVES)
+ life.show ();
life_images.add (life);
- lives_grid.attach (life, i % 6, i/6);
+ lives_grid.attach (life, i % 6, i / 6);
}
}
@@ -872,21 +873,12 @@ private class PlayerScoreBox : Gtk.Box
public void update_lives (int lives_left)
{
/* Remove lost lives - if any */
- for (int i = life_images.size; i > lives_left; i--)
- {
- var life = life_images.poll ();
- life.hide ();
- }
+ for (int i = life_images.size - 1; i >= lives_left; i--)
+ life_images[i].set_opacity (0);
/* Add new lives - if any */
- for (int i = life_images.size; i < lives_left; i++)
- {
- var life = new Gtk.Image.from_pixbuf (life_images.first ().get_pixbuf ());
- life.show ();
-
- life_images.add (life);
- lives_grid.attach (life, i % 6, i/6);
- }
+ for (int i = 0; i < lives_left; i++)
+ life_images[i].set_opacity (1);
}
}
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 576c08a..2386b1b 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -53,10 +53,10 @@ public class NibblesGame : Object
public WarpManager warp_manager;
public int numhumans;
- public int numai;
+ public int numai = NUMAI;
public int numworms;
- public int speed = 4;
+ public int speed = 2;
public bool is_running = false;
public bool is_paused { get; private set; }
@@ -429,7 +429,7 @@ public class NibblesGame : Object
}
break;
case BonusType.LIFE:
- worm.lives++;
+ worm.add_life ();
break;
case BonusType.REVERSE:
reverse_worms (worm);
diff --git a/src/worm.vala b/src/worm.vala
index 879468a..455d1f4 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -22,7 +22,9 @@
public class Worm : Object
{
public const int STARTING_LENGTH = 5;
- private const int STARTING_LIVES = 6;
+ public const int STARTING_LIVES = 6;
+ public const int MAX_LIVES = 12;
+
public const int GROW_FACTOR = 4;
public Position starting_position { get; private set; }
@@ -232,7 +234,15 @@ public class Worm : Object
move (walls);
}
- public void lose_life ()
+ public void add_life ()
+ {
+ if (lives > MAX_LIVES)
+ return;
+
+ lives++;
+ }
+
+ private void lose_life ()
{
lives--;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]