[gnome-nibbles/arnaudb/modernize-code: 18/58] Improve Boni API.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/modernize-code: 18/58] Improve Boni API.
- Date: Wed, 10 Jun 2020 17:14:26 +0000 (UTC)
commit 0071e74f00e297839fd42e8f48384d48673224c3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed May 27 13:21:29 2020 +0200
Improve Boni API.
src/boni.vala | 26 +++++++++++++++++++++++---
src/nibbles-game.vala | 21 +++++++++------------
2 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/src/boni.vala b/src/boni.vala
index 9d6c10b..e4e9d7e 100644
--- a/src/boni.vala
+++ b/src/boni.vala
@@ -47,13 +47,11 @@ private class Boni : Object
{
internal Gee.LinkedList<Bonus> bonuses = new Gee.LinkedList<Bonus> ();
- internal int missed { internal get; internal set; default = 0; }
internal int numleft { internal get; internal set; default = 8; }
internal int numboni { internal get; private set; default = 8; }
private int numbonuses = 0;
private const int MAX_BONUSES = 100;
- internal const int MAX_MISSED = 2;
internal signal void bonus_added ();
internal signal void bonus_removed (Bonus bonus);
@@ -86,7 +84,7 @@ private class Boni : Object
internal void reset (int numworms)
{
bonuses.clear ();
- missed = 0;
+ reset_missed ();
numboni = 8 + numworms;
numbonuses = 0;
numleft = numboni;
@@ -107,4 +105,26 @@ private class Boni : Object
return null;
}
+
+ /*\
+ * * missed
+ \*/
+
+ private uint8 missed = 0;
+ private const uint8 MAX_MISSED = 2;
+
+ internal inline bool too_many_missed ()
+ {
+ return missed > MAX_MISSED;
+ }
+
+ internal inline void increase_missed ()
+ {
+ missed++;
+ }
+
+ private inline void reset_missed ()
+ {
+ missed = 0;
+ }
}
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index b89a083..fb3d648 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -222,7 +222,7 @@ private class NibblesGame : Object
internal void move_worms ()
{
- if (boni.missed > Boni.MAX_MISSED)
+ if (boni.too_many_missed ())
{
foreach (var worm in worms)
{
@@ -238,18 +238,15 @@ private class NibblesGame : Object
{
if (bonus.countdown-- == 0)
{
- if (bonus.bonus_type == BonusType.REGULAR && !bonus.fake)
- {
- found.add (bonus);
- boni.remove_bonus (board, bonus);
- boni.missed++;
+ bool missed = bonus.bonus_type == BonusType.REGULAR && !bonus.fake;
- add_bonus (true);
- }
- else
+ found.add (bonus);
+ boni.remove_bonus (board, bonus);
+
+ if (missed)
{
- found.add (bonus);
- boni.remove_bonus (board, bonus);
+ boni.increase_missed ();
+ add_bonus (true);
}
}
}
@@ -362,7 +359,7 @@ private class NibblesGame : Object
}
boni.add_bonus (board, x, y, BonusType.REGULAR, false, 300);
}
- else if (boni.missed <= Boni.MAX_MISSED)
+ else if (!boni.too_many_missed ())
{
if (Random.int_range (0, 7) != 0)
good = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]