[gnome-nibbles/arnaudb/modernize-code: 14/58] Some cleanings.



commit 3c245e1eb54101d1f7c587b5143c65d8827d9f81
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue May 26 21:51:23 2020 +0200

    Some cleanings.

 src/boni.vala | 22 +++++++++++-----------
 src/warp.vala | 12 ++++++------
 src/worm.vala | 19 +++++++------------
 3 files changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/src/boni.vala b/src/boni.vala
index 1964093..9d6c10b 100644
--- a/src/boni.vala
+++ b/src/boni.vala
@@ -47,9 +47,9 @@ private class Boni : Object
 {
     internal Gee.LinkedList<Bonus> bonuses = new Gee.LinkedList<Bonus> ();
 
-    internal int missed = 0;
-    internal int numleft = 8;
-    internal int numboni = 8;
+    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;
@@ -65,9 +65,9 @@ private class Boni : Object
 
         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    , 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 ();
         numbonuses++;
@@ -75,9 +75,9 @@ private class Boni : Object
 
     internal void remove_bonus (int[,] board, Bonus bonus)
     {
-        board[bonus.x, bonus.y] = NibblesGame.EMPTYCHAR;
-        board[bonus.x + 1, bonus.y] = NibblesGame.EMPTYCHAR;
-        board[bonus.x, bonus.y + 1] = NibblesGame.EMPTYCHAR;
+        board[bonus.x    , bonus.y    ] = NibblesGame.EMPTYCHAR;
+        board[bonus.x + 1, bonus.y    ] = NibblesGame.EMPTYCHAR;
+        board[bonus.x    , bonus.y + 1] = NibblesGame.EMPTYCHAR;
         board[bonus.x + 1, bonus.y + 1] = NibblesGame.EMPTYCHAR;
 
         bonus_removed (bonus);
@@ -96,8 +96,8 @@ private class Boni : Object
     {
         foreach (var bonus in bonuses)
         {
-            if ((x == bonus.x     && y == bonus.y)
-             || (x == bonus.x + 1 && y == bonus.y)
+            if ((x == bonus.x     && y == bonus.y    )
+             || (x == bonus.x + 1 && y == bonus.y    )
              || (x == bonus.x     && y == bonus.y + 1)
              || (x == bonus.x + 1 && y == bonus.y + 1))
             {
diff --git a/src/warp.vala b/src/warp.vala
index 207947a..57d8d9b 100644
--- a/src/warp.vala
+++ b/src/warp.vala
@@ -97,9 +97,9 @@ private class WarpManager: Object
                 warp_added (warp);
             }
 
-            board[x, y] = NibblesGame.WARPCHAR;
-            board[x + 1, y] = NibblesGame.WARPCHAR;
-            board[x, y + 1] = NibblesGame.WARPCHAR;
+            board[x    , y    ] = NibblesGame.WARPCHAR;
+            board[x + 1, y    ] = NibblesGame.WARPCHAR;
+            board[x    , y + 1] = NibblesGame.WARPCHAR;
             board[x + 1, y + 1] = NibblesGame.WARPCHAR;
         }
     }
@@ -108,9 +108,9 @@ private class WarpManager: Object
     {
         foreach (var warp in warps)
         {
-            if ((x == warp.x && y == warp.y)
-             || (x == warp.x + 1 && y == warp.y)
-             || (x == warp.x && y == warp.y + 1)
+            if ((x == warp.x     && y == warp.y    )
+             || (x == warp.x + 1 && y == warp.y    )
+             || (x == warp.x     && y == warp.y + 1)
              || (x == warp.x + 1 && y == warp.y + 1))
                 return warp;
         }
diff --git a/src/worm.vala b/src/worm.vala
index d802e7d..5fe6cd1 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -53,7 +53,7 @@ private class Worm : Object
 
     internal Position starting_position { internal get; private set; }
 
-    internal int id { internal get; private set; }
+    public int id { internal get; protected construct; }
 
     internal bool is_human;
     internal bool keypress = false;
@@ -61,9 +61,9 @@ private class Worm : Object
     internal bool is_materialized { internal get; private set; default = true; }
     private int rounds_dematerialized;
 
-    internal int lives { get; set; }
-    internal int change;
-    internal int score { get; set; }
+    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 int length
     {
@@ -87,9 +87,9 @@ private class Worm : Object
 
     private WormDirection starting_direction;
 
-    private Gee.ArrayQueue<WormDirection> key_queue;
+    private Gee.ArrayQueue<WormDirection> key_queue = new Gee.ArrayQueue<WormDirection> ();
 
-    internal Gee.LinkedList<Position?> list { get; private set; }
+    internal Gee.LinkedList<Position?> list { internal get; private set; default = new 
Gee.LinkedList<Position?> (); }
 
     internal signal void added ();
     internal signal void finish_added ();
@@ -104,12 +104,7 @@ private class Worm : Object
 
     internal Worm (int id)
     {
-        this.id = id;
-        lives = STARTING_LIVES;
-        score = 0;
-        change = 0;
-        list = new Gee.LinkedList<Position?> ();
-        key_queue = new Gee.ArrayQueue<WormDirection> ();
+        Object (id: id);
     }
 
     internal void set_start (int xhead, int yhead, WormDirection direction)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]