[gnome-nibbles] Refactor nibbles-game.vala
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Refactor nibbles-game.vala
- Date: Mon, 26 Oct 2015 00:23:02 +0000 (UTC)
commit fea54d76eebed60d6733ec24f1b896e8505eab84
Author: Iulian Radu <iulian radu67 gmail com>
Date: Fri Sep 18 15:33:52 2015 +0300
Refactor nibbles-game.vala
https://bugzilla.gnome.org/show_bug.cgi?id=754608
src/nibbles-game.vala | 57 ++++++++++++++++++++++++-------------------------
1 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 742a65c..e528daf 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -19,11 +19,15 @@
// This is a fairly literal translation of the LGPLv2+ original by
// Sean MacIsaac, Ian Peters, Guillaume BĂ©land.
-public class NibblesGame : Object
+public enum GameStatus
{
- public int tile_size;
- public int start_level;
+ GAMEOVER,
+ VICTORY,
+ NEWROUND
+}
+public class NibblesGame : Object
+{
public const int MINIMUM_TILE_SIZE = 7;
public const int GAMEDELAY = 35;
@@ -35,37 +39,42 @@ public class NibblesGame : Object
public const int WIDTH = 92;
public const int HEIGHT = 66;
-
public const int CAPACITY = WIDTH * HEIGHT;
public const char EMPTYCHAR = 'a';
public const char WORMCHAR = 'w';
public const char WARPCHAR = 'W';
- public const int MAX_LEVEL = 26;
+ private const int MAX_LEVEL = 26;
- public int current_level;
- public int[,] board;
-
- public Gee.LinkedList<Worm> worms;
+ public int start_level { get; private set; }
+ public int current_level { get; private set; }
+ public int speed { get; private set; default = 2; }
- public Boni boni;
- public WarpManager warp_manager;
+ /* Board data */
+ public int tile_size { get; set; }
+ public int[,] board;
- public int numhumans;
- public int numai;
- public int numworms;
+ /* Worms data */
+ public int numhumans { get; set; }
+ private int numai;
+ public int numworms { get; private set; }
- public int speed = 2;
+ /* Game models */
+ public Gee.LinkedList<Worm> worms { get; private set; }
+ public Boni boni { get; private set; }
+ public WarpManager warp_manager { get; private set; }
+ public Gee.HashMap<Worm, WormProperties?> worm_props { get; private set; }
- public bool is_running = false;
+ /* Game controls */
+ public bool is_running { get; private set; default = false; }
public bool is_paused { get; private set; }
- public bool fakes = false;
-
private uint main_id = 0;
private uint add_bonus_id = 0;
+ public bool fakes { get; private set; default = false; }
+
public signal void worm_moved (Worm worm);
public signal void bonus_applied (Worm worm);
public signal void log_score (int score);
@@ -73,8 +82,6 @@ public class NibblesGame : Object
public signal void restart_game ();
public signal void level_completed ();
- public Gee.HashMap<Worm, WormProperties?> worm_props;
-
public NibblesGame (Settings settings)
{
boni = new Boni (numworms);
@@ -96,7 +103,6 @@ public class NibblesGame : Object
public void start ()
{
- stderr.printf("[Debug] Game started\n");
is_running = true;
main_id = Timeout.add (GAMEDELAY * speed, main_loop_cb);
@@ -156,8 +162,8 @@ public class NibblesGame : Object
else if (status == GameStatus.VICTORY)
{
end ();
- var winner = get_winner ();
+ var winner = get_winner ();
if (winner == null)
return Source.REMOVE;
@@ -582,10 +588,3 @@ public class NibblesGame : Object
return false;
}
}
-
-public enum GameStatus
-{
- GAMEOVER,
- VICTORY,
- NEWROUND
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]