[gnome-nibbles/arnaudb/fix-level-25: 6/8] Allow changing start-level while game runs.



commit 74e1d83c9b4e9ae46e9d370d32620e0dc1502248
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jun 24 18:03:41 2020 +0200

    Allow changing start-level while game runs.

 src/nibbles-game.vala   | 7 ++++---
 src/nibbles-window.vala | 5 ++---
 2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index c4b567d..31a03d7 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -40,7 +40,7 @@ private class NibblesGame : Object
 
     internal const int MAX_LEVEL = 26;
 
-    public int start_level      { internal get; protected construct; }
+    public bool skip_score      { internal get; protected construct set; }
     public int current_level    { internal get; protected construct set; }
     public int speed            { internal get; internal construct set; }
 
@@ -87,7 +87,7 @@ private class NibblesGame : Object
 
     internal NibblesGame (int start_level, int speed, bool fakes, int width, int height, bool no_random = 
false)
     {
-        Object (start_level: start_level, current_level: start_level, speed: speed, fakes: fakes, width: 
width, height: height);
+        Object (skip_score: (start_level != 1), current_level: start_level, speed: speed, fakes: fakes, 
width: width, height: height);
 
         Random.set_seed (no_random ? 42 : (uint32) time_t ());
     }
@@ -285,8 +285,9 @@ private class NibblesGame : Object
         start (/* add initial bonus */ false);
     }
 
-    internal inline void reset ()
+    internal inline void reset (int start_level)
     {
+        skip_score = start_level != 1;
         current_level = start_level;
         is_paused = false;
     }
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 79e51b9..59f72af 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -196,7 +196,6 @@ private class NibblesWindow : ApplicationWindow
 
         // game properties
         settings.set_int ("tile-size", view.tile_size);     // TODO why?!
-        settings.set_int ("start-level", game.start_level);
         settings.set_int ("speed", game.speed);
         settings.set_boolean ("fakes", game.fakes);
         settings.apply ();
@@ -261,7 +260,7 @@ private class NibblesWindow : ApplicationWindow
 
         if (game.is_paused)
             set_pause_button_label (/* paused */ false);
-        game.reset ();
+        game.reset (settings.get_int ("start-level"));
 
         view.new_level (game.current_level);
         view.connect_worm_signals ();
@@ -718,7 +717,7 @@ private class NibblesWindow : ApplicationWindow
             return;
         }
 
-        if (game.start_level != 1)
+        if (game.skip_score)
         {
             game_over (score, lowest_high_score, level_reached);
             return;


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