[gnome-mines] Use start-time mine calculation instead of click-time (bgo#773782)



commit 55e89268aa096c0185b834fc3a5be8c918fdceff
Author: Robert Roth <robert roth off gmail com>
Date:   Wed Nov 2 08:28:02 2016 +0200

    Use start-time mine calculation instead of click-time (bgo#773782)

 src/minefield.vala |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/src/minefield.vala b/src/minefield.vala
index 2244524..0224961 100644
--- a/src/minefield.vala
+++ b/src/minefield.vala
@@ -25,6 +25,9 @@ protected class Location : Object
 
     /* Flag */
     public FlagType flag = FlagType.NONE;
+
+    /* Number of mines in the neighbourhood */
+    public int adjacent_mines = 0;
 }
 
 /* Table of offsets to adjacent squares */
@@ -304,15 +307,7 @@ public class Minefield : Object
 
     public uint get_n_adjacent_mines (uint x, uint y)
     {
-        uint n = 0;
-        foreach (var neighbour in neighbour_map)
-        {
-            var nx = (int) x + neighbour.x;
-            var ny = (int) y + neighbour.y;
-            if (is_location (nx, ny) && has_mine (nx, ny))
-                n++;
-        }
-        return n;
+        return locations[x, y].adjacent_mines;
     }
 
     public bool has_flag_warning (uint x, uint y)
@@ -364,6 +359,13 @@ public class Minefield : Object
                 {
                     locations[rx, ry].has_mine = true;
                     n++;
+                    foreach (var neighbour in neighbour_map)
+                    {
+                        var nx = rx + neighbour.x;
+                        var ny = ry + neighbour.y;
+                        if (is_location (nx, ny))
+                            locations[nx, ny].adjacent_mines++;
+                    }
                 }
             }
         }


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