[quadrapassel] Fix for incorrect preview shape when difficult blocks is selected



commit 6fe9a1bc968cc1977648d19ad07219ca990ae096
Author: John Ward <john johnward net>
Date:   Mon Sep 14 23:42:41 2020 +0100

    Fix for incorrect preview shape when difficult blocks is selected

 src/game.vala | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 256d1fe..7a71047 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -308,7 +308,7 @@ public class Game : Object
         this.pick_difficult_blocks = pick_difficult_blocks;
 
         blocks = new Block[columns, lines];
-        /* Start with some pre-filled spaces */
+        /* Start with some shape_landed-filled spaces */
         for (var y = 0; y < height; y++)
         {
             /* Pick at least one column to be empty */
@@ -363,6 +363,7 @@ public class Game : Object
     public void start ()
     {
         has_started = true;
+        make_next_shape();
         add_shape ();
         setup_drop_timer ();
         started ();
@@ -500,18 +501,23 @@ public class Game : Object
         return true;
     }
 
-    private void add_shape ()
+    private void make_next_shape ()
     {
-        if (pick_difficult_blocks) {
-            var difficult_shapes = pick_difficult_shapes ();
-            shape = difficult_shapes[0];
-            next_shape = difficult_shapes[1];
+        if (pick_difficult_blocks)
+        {
+            next_shape = pick_difficult_shapes ();
         }
         else
         {
-            shape = (owned) next_shape;
             next_shape = pick_random_shape ();
         }
+    }
+
+    private void add_shape ()
+    {
+        shape = (owned) next_shape;
+
+        make_next_shape();
 
         foreach (var b in shape.blocks)
         {
@@ -541,7 +547,7 @@ public class Game : Object
         return make_shape (Random.int_range (0, NCOLORS), Random.int_range (0, 4));
     }
 
-    private Shape[] pick_difficult_shapes ()
+    private Shape pick_difficult_shapes ()
     {
        /* The algorithm comes from Federico Poloni's "bastet" game */
         var metrics = new int[NCOLORS];
@@ -622,24 +628,22 @@ public class Game : Object
             }
         }
 
+        var new_shape = new Shape();
         /* Actually choose a piece */
         var rnd = Random.int_range (0, 99);
         if (rnd < 75)
-            shape = make_shape (possible_types[0], Random.int_range (0, 4));
+            new_shape = make_shape (possible_types[0], Random.int_range (0, 4));
         else if (rnd < 92)
-            shape = make_shape (possible_types[1], Random.int_range (0, 4));
+            new_shape = make_shape (possible_types[1], Random.int_range (0, 4));
         else if (rnd < 98)
-            shape = make_shape (possible_types[2], Random.int_range (0, 4));
+            new_shape = make_shape (possible_types[2], Random.int_range (0, 4));
         else
-            shape = make_shape (possible_types[3], Random.int_range (0, 4));
+            new_shape = make_shape (possible_types[3], Random.int_range (0, 4));
 
-       /* Look, this one is a great fit. It would be a shame if it wouldn't be given next */
-       next_shape = make_shape (possible_types[NCOLORS - 1], Random.int_range (0, 4));
+           /* Look, this one is a great fit. It would be a shame if it wouldn't be given next */
+           //next_shape = make_shape (possible_types[NCOLORS - 1], Random.int_range (0, 4));
 
-       var shapes = new Shape[2];
-       shapes[0] = shape;
-       shapes[1] = next_shape;
-       return shapes;
+           return new_shape;
     }
 
     private Shape make_shape (int type, int rotation)


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