[gnome-nibbles/arnaudb/modernize-code: 41/58] Make one more variable private.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/modernize-code: 41/58] Make one more variable private.
- Date: Wed, 10 Jun 2020 17:16:23 +0000 (UTC)
commit 8a0583e75029ff6a61bfa20d54ba6c987c659cbd
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri May 29 23:58:17 2020 +0200
Make one more variable private.
Unhappy to keep bonus_removed,
but I cannot find another way.
src/boni.vala | 20 +++++++++-----------
src/nibbles-game.vala | 23 ++++++++++++++++-------
src/nibbles-view.vala | 4 ++--
3 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/src/boni.vala b/src/boni.vala
index 8a6611e..1e1a678 100644
--- a/src/boni.vala
+++ b/src/boni.vala
@@ -49,26 +49,24 @@ private class Boni : Object
internal int numleft { internal get; internal set; default = 8; }
internal int numboni { internal get; private set; default = 8; }
- private int numbonuses = 0;
+ private uint16 numbonuses = 0;
private const int MAX_BONUSES = 100;
- internal signal void bonus_added (Bonus bonus);
internal signal void bonus_removed (Bonus bonus);
- internal void add_bonus (int[,] board, int x, int y, BonusType bonus_type, bool fake, int countdown)
+ internal bool add_bonus (int[,] board, owned Bonus bonus)
{
- if (numbonuses == MAX_BONUSES)
- return;
+ if (numbonuses >= MAX_BONUSES)
+ return false;
- var bonus = new Bonus (x, y, bonus_type, fake, countdown);
bonuses.add (bonus);
- board[x , y ] = bonus_type + 'A';
- board[x + 1, y ] = bonus_type + 'A';
- board[x , y + 1] = bonus_type + 'A';
- board[x + 1, y + 1] = bonus_type + 'A';
- bonus_added (bonus);
+ board[bonus.x , bonus.y ] = bonus.bonus_type + 'A';
+ board[bonus.x + 1, bonus.y ] = bonus.bonus_type + 'A';
+ board[bonus.x , bonus.y + 1] = bonus.bonus_type + 'A';
+ board[bonus.x + 1, bonus.y + 1] = bonus.bonus_type + 'A';
numbonuses++;
+ return true;
}
internal void remove_bonus (int[,] board, Bonus bonus)
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 756fb3e..f60fdc0 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -63,9 +63,9 @@ private class NibblesGame : Object
/* Game models */
public Gee.LinkedList<Worm> worms { internal get; default = new
Gee.LinkedList<Worm> (); }
- public Boni boni { internal get; default = new Boni (); }
public Gee.HashMap<Worm, WormProperties?> worm_props { internal get; default = new Gee.HashMap<Worm,
WormProperties?> (); }
+ private Boni boni = new Boni ();
private WarpManager warp_manager = new WarpManager ();
/* Game controls */
@@ -82,10 +82,13 @@ private class NibblesGame : Object
internal signal void animate_end_game ();
internal signal void level_completed ();
internal signal void warp_added (int x, int y);
+ internal signal void bonus_added (Bonus bonus);
+ internal signal void bonus_removed (Bonus bonus);
construct
{
warp_manager.warp_added.connect ((warp) => warp_added (warp.x, warp.y));
+ boni.bonus_removed.connect ((bonus) => bonus_removed (bonus));
}
internal NibblesGame (int tile_size, int start_level, int speed, bool fakes, bool no_random = false)
@@ -418,7 +421,7 @@ private class NibblesGame : Object
if (regular)
{
if ((Random.int_range (0, 7) == 0) && fakes)
- boni.add_bonus (board, x, y, BonusType.REGULAR, true, 300);
+ _add_bonus (x, y, BonusType.REGULAR, true, 300);
good = false;
while (!good)
@@ -436,7 +439,7 @@ private class NibblesGame : Object
if (board[x + 1, y + 1] != EMPTYCHAR)
good = false;
}
- boni.add_bonus (board, x, y, BonusType.REGULAR, false, 300);
+ _add_bonus (x, y, BonusType.REGULAR, false, 300);
}
else if (!boni.too_many_missed ())
{
@@ -460,17 +463,17 @@ private class NibblesGame : Object
case 7:
case 8:
case 9:
- boni.add_bonus (board, x, y, BonusType.HALF, good, 200);
+ _add_bonus (x, y, BonusType.HALF, good, 200);
break;
case 10:
case 11:
case 12:
case 13:
case 14:
- boni.add_bonus (board, x, y, BonusType.DOUBLE, good, 150);
+ _add_bonus (x, y, BonusType.DOUBLE, good, 150);
break;
case 15:
- boni.add_bonus (board, x, y, BonusType.LIFE, good, 100);
+ _add_bonus (x, y, BonusType.LIFE, good, 100);
break;
case 16:
case 17:
@@ -478,11 +481,17 @@ private class NibblesGame : Object
case 19:
case 20:
if (numworms > 1)
- boni.add_bonus (board, x, y, BonusType.REVERSE, good, 150);
+ _add_bonus (x, y, BonusType.REVERSE, good, 150);
break;
}
}
}
+ private inline void _add_bonus (int x, int y, BonusType bonus_type, bool fake, int countdown)
+ {
+ Bonus bonus = new Bonus (x, y, bonus_type, fake, countdown);
+ if (boni.add_bonus (board, bonus))
+ bonus_added (bonus);
+ }
private void apply_bonus (Bonus bonus, Worm worm)
{
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 0ea5959..447fe78 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -135,8 +135,8 @@ private class NibblesView : GtkClutter.Embed
SignalHandler.disconnect_matched (_game, SignalMatchType.DATA, 0, 0, null, null, this);
_game = value;
- _game.boni.bonus_added.connect (bonus_added_cb);
- _game.boni.bonus_removed.connect (bonus_removed_cb);
+ _game.bonus_added.connect (bonus_added_cb);
+ _game.bonus_removed.connect (bonus_removed_cb);
_game.bonus_applied.connect (bonus_applied_cb);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]