[lightsoff] Implemented moves counter (bgo #691908)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lightsoff] Implemented moves counter (bgo #691908)
- Date: Thu, 1 Jan 2015 22:30:09 +0000 (UTC)
commit e878aeff4ae7de0f0aea8aca047d43041d458ec0
Author: Robert Roth <robert roth off gmail com>
Date: Thu Jan 1 17:19:27 2015 +0200
Implemented moves counter (bgo #691908)
src/board-view.vala | 11 ++++++++++-
src/game-view.vala | 8 +++++++-
src/lightsoff.vala | 9 +++++++--
3 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/src/board-view.vala b/src/board-view.vala
index 3ffac7e..fe3f562 100644
--- a/src/board-view.vala
+++ b/src/board-view.vala
@@ -77,10 +77,16 @@ public class BoardView : Clutter.Group
private Clutter.Texture off_texture;
private Clutter.Texture on_texture;
private Light[,] lights;
-
+ private int _moves = 0;
public bool playable = true;
+ public int moves
+ {
+ get { return _moves;}
+ }
+
public signal void game_won ();
+ public signal void light_toggled ();
public BoardView (Clutter.Texture off_texture, Clutter.Texture on_texture)
{
@@ -108,6 +114,7 @@ public class BoardView : Clutter.Group
add_child (l);
}
}
+ _moves = 0;
}
public void get_light_position (int x, int y, out float xx, out float yy)
@@ -176,6 +183,8 @@ public class BoardView : Clutter.Group
int x, y;
find_light ((Light) actor, out x, out y);
toggle_light (x, y);
+ _moves += 1;
+ light_toggled ();
}
// Toggle a light and those in each cardinal direction around it.
diff --git a/src/game-view.vala b/src/game-view.vala
index b2348cc..43da317 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -38,6 +38,7 @@ public class GameView : Clutter.Group
private int last_sign = 0;
public signal void level_changed (int level);
+ public signal void moves_changed (int moves);
public GameView (int level)
{
@@ -83,8 +84,8 @@ public class GameView : Clutter.Group
var view = new BoardView (off_texture, on_texture);
view.load_level (level);
view.game_won.connect (game_won_cb);
+ view.light_toggled.connect (light_toggled_cb);
view.playable = false;
-
return view;
}
@@ -103,6 +104,11 @@ public class GameView : Clutter.Group
actor_remove_queue = null;
}
+ private void light_toggled_cb ()
+ {
+ moves_changed (board_view.moves);
+ }
+
// The player won the game; create a new board, update the level count,
// and transition between the two boards in a random direction.
private void game_won_cb ()
diff --git a/src/lightsoff.vala b/src/lightsoff.vala
index ec74556..4b629c2 100644
--- a/src/lightsoff.vala
+++ b/src/lightsoff.vala
@@ -94,6 +94,7 @@ public class LightsOff : Gtk.Application
game_view = new GameView (settings.get_int ("level"));
game_view.level_changed.connect (level_changed_cb);
+ game_view.moves_changed.connect (update_subtitle);
game_view.show ();
stage.add_child (game_view);
@@ -101,12 +102,16 @@ public class LightsOff : Gtk.Application
clutter_embed.set_size_request ((int) stage.width, (int) stage.height);
}
+ private void update_subtitle (int moves)
+ {
+ headerbar.subtitle = ngettext ("%d move", "%d moves", moves).printf (moves);
+ }
+
private void update_title (int level)
{
/* The title of the window, %d is the level number */
headerbar.title = _("Level %d").printf (level);
- /* Subtitle of the window when playing level one. */
- headerbar.subtitle = level == 1 ? _("Turn off all the lights!") : null;
+ update_subtitle (0);
}
private void previous_level_cb ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]