[gnome-nibbles/arnaudb/use-uint8: 31/33] Use uint8 even more.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/use-uint8: 31/33] Use uint8 even more.
- Date: Thu, 9 Jul 2020 15:15:15 +0000 (UTC)
commit d415332863d585c3b2ffc118ff24fb2ec3107651
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Jul 3 01:24:23 2020 +0200
Use uint8 even more.
src/nibbles-game.vala | 4 ++--
src/scoreboard.vala | 12 ++++++------
src/worm.vala | 17 ++++++++++-------
3 files changed, 18 insertions(+), 15 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index caa2237..ca94e4c 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -659,9 +659,9 @@ private class NibblesGame : Object
{
if (worm.lives > 0)
worms_left += 1;
- else if (worm.is_human && worm.lives <= 0)
+ else if (worm.is_human && worm.lives == 0)
return GameStatus.GAMEOVER;
- else if (numhumans == 0 && worm.lives <= 0)
+ else if (numhumans == 0 && worm.lives == 0)
return GameStatus.GAMEOVER;
}
diff --git a/src/scoreboard.vala b/src/scoreboard.vala
index f5e9640..d34f042 100644
--- a/src/scoreboard.vala
+++ b/src/scoreboard.vala
@@ -65,12 +65,12 @@ private class PlayerScoreBox : Box
private Gee.LinkedList<Image> life_images = new Gee.LinkedList<Image> ();
- internal PlayerScoreBox (string name, Pango.Color color, int score, int lives_left, Gdk.Pixbuf
life_pixbuf)
+ internal PlayerScoreBox (string name, Pango.Color color, int score, uint8 lives_left, Gdk.Pixbuf
life_pixbuf)
{
name_label.set_markup ("<span color=\"" + color.to_string () + "\">" + name + "</span>");
score_label.set_label (score.to_string ());
- for (int i = 0; i < Worm.MAX_LIVES; i++)
+ for (uint8 i = 0; i < Worm.MAX_LIVES; i++)
{
var life = new Image.from_pixbuf (life_pixbuf);
life.show ();
@@ -83,7 +83,7 @@ private class PlayerScoreBox : Box
}
}
- internal void update (int score, int lives_left)
+ internal void update (int score, uint8 lives_left)
{
update_score (score);
update_lives (lives_left);
@@ -94,14 +94,14 @@ private class PlayerScoreBox : Box
score_label.set_label (score.to_string ());
}
- internal void update_lives (int lives_left)
+ internal void update_lives (uint8 lives_left)
{
/* Remove lost lives - if any */
- for (int i = life_images.size - 1; i >= lives_left; i--)
+ for (uint8 i = (uint8) life_images.size - 1; i >= lives_left; i--)
life_images[i].set_opacity (0);
/* Add new lives - if any */
- for (int i = 0; i < lives_left; i++)
+ for (uint8 i = 0; i < lives_left; i++)
life_images[i].set_opacity (1);
}
}
diff --git a/src/worm.vala b/src/worm.vala
index b9df10e..708d37d 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -119,8 +119,8 @@ private class WormProperties : Object
private class Worm : Object
{
private const int STARTING_LENGTH = 5;
- internal const int STARTING_LIVES = 6;
- internal const int MAX_LIVES = 12;
+ internal const uint8 STARTING_LIVES = 6;
+ internal const uint8 MAX_LIVES = 12;
internal const int GROW_FACTOR = 4;
@@ -134,9 +134,9 @@ private class Worm : Object
internal bool is_materialized { internal get; private set; default = true; }
private int rounds_dematerialized;
- internal int lives { internal get; internal set; default = STARTING_LIVES; }
- internal int change { internal get; internal set; default = 0; }
- internal int score { internal get; internal set; default = 0; }
+ internal uint8 lives { internal get; internal set; default = STARTING_LIVES; }
+ internal int change { internal get; internal set; default = 0; }
+ internal int score { internal get; internal set; default = 0; }
internal int length
{
@@ -348,6 +348,9 @@ private class Worm : Object
private inline void lose_life ()
{
+ if (lives == 0)
+ return;
+
lives--;
}
@@ -412,7 +415,7 @@ private class Worm : Object
internal bool handle_keypress (uint keyval, Gee.HashMap<Worm, WormProperties> worm_props)
{
- if (lives <= 0 || is_stopped)
+ if (lives == 0 || is_stopped)
return false;
WormProperties properties;
@@ -713,7 +716,7 @@ private class Worm : Object
/* Make sure we are at least avoiding walls.
* Mostly other snakes should avoid our head.
*/
- for (int dir = 1; dir <= 4; dir++)
+ for (uint8 dir = 1; dir <= 4; dir++)
{
if (opposite == (WormDirection) dir)
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]