[gnome-2048] Add basic congratulations on value reached
- From: Juan R. Garcia Blanco <juanrgar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Add basic congratulations on value reached
- Date: Fri, 13 Feb 2015 23:39:08 +0000 (UTC)
commit 02e4e6ee4a49007e2e528452e76f5d46f52e7be8
Author: Juan R. García Blanco <juanrgar gmail com>
Date: Sat Feb 14 00:38:40 2015 +0100
Add basic congratulations on value reached
data/org.gnome.2048.gschema.xml | 5 +++++
src/application.vala | 6 +++++-
src/game.vala | 10 ++++++++++
src/grid.vala | 21 +++++++++++++++++++++
4 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.2048.gschema.xml b/data/org.gnome.2048.gschema.xml
index 8ae3939..4677fff 100644
--- a/data/org.gnome.2048.gschema.xml
+++ b/data/org.gnome.2048.gschema.xml
@@ -25,5 +25,10 @@
<summary>Number of columns</summary>
<description>Game grid number of columns.</description>
</key>
+ <key name="target-value" type="i">
+ <default>32</default>
+ <summary>Target value</summary>
+ <description>Tile value at which user is congratulated.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/application.vala b/src/application.vala
index 7ad0c67..74d0465 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -121,6 +121,10 @@ public class Application : Gtk.Application
_header_bar.subtitle = _("Game Over");
debug ("finished");
});
+ _game.target_value_reached.connect ((s, v) => {
+ _header_bar.subtitle = _("Congratulations!!");
+ debug ("target value reached");
+ });
}
private void _create_window (Gtk.Builder builder)
@@ -189,7 +193,7 @@ public class Application : Gtk.Application
_about_dialog.comments = _("A clone of 2048 for GNOME");
_about_dialog.authors = {"Juan R. García Blanco"};
- _about_dialog.copyright = "Copyright © 2014 Juan R. García Blanco";
+ _about_dialog.copyright = "Copyright © 2014-2015 Juan R. García Blanco";
_about_dialog.version = "0.1";
_about_dialog.website = "http://www.gnome.org";
_about_dialog.license_type = Gtk.License.GPL_3_0;
diff --git a/src/game.vala b/src/game.vala
index 96f32f4..d80eb58 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -55,6 +55,7 @@ public class Game : GLib.Object
private uint _resize_view_id;
public signal void finished ();
+ public signal void target_value_reached (uint val);
public Game (GLib.Settings settings)
{
@@ -66,6 +67,9 @@ public class Game : GLib.Object
int cols = _settings.get_int ("cols");
_grid = new Grid (rows, cols);
+ uint target_value = _settings.get_int ("target-value");
+ _grid.target_value = target_value;
+
_to_move = new Gee.LinkedList<TileMovement?> ();
_to_hide = new Gee.LinkedList<TileMovement?> ();
_to_show = new Gee.LinkedList<Tile?> ();
@@ -658,6 +662,12 @@ public class Game : GLib.Object
_to_move.clear ();
_to_show.clear ();
+ if (_grid.target_value_reached) {
+ target_value_reached (_grid.target_value);
+ _grid.target_value_reached = false;
+ _grid.target_value = 0;
+ }
+
if (_grid.is_finished ())
finished ();
}
diff --git a/src/grid.vala b/src/grid.vala
index 042e406..d402b65 100644
--- a/src/grid.vala
+++ b/src/grid.vala
@@ -26,6 +26,7 @@ public class Grid : GLib.Object
_grid = new uint[rows, cols];
clear ();
+ _target_value = 0;
}
public int rows {
@@ -36,6 +37,14 @@ public class Grid : GLib.Object
get; set;
}
+ public uint target_value {
+ get; set;
+ }
+
+ public bool target_value_reached {
+ get; set;
+ }
+
public void clear ()
{
for (uint i = 0; i < _grid.length[0]; i++) {
@@ -62,6 +71,7 @@ public class Grid : GLib.Object
if (_grid[pos.row,pos.col] == 0) {
_grid[pos.row,pos.col] = val;
+ _check_target_value_reached (val);
tile = { pos, val };
return true;
}
@@ -132,6 +142,7 @@ public class Grid : GLib.Object
_grid[cur.row,cur.col] = 0;
_grid[match.row,match.col] = 0;
_grid[free.row,free.col] = val*2;
+ _check_target_value_reached (val*2);
free.row--;
} else if (free.row != _rows) {
@@ -213,6 +224,7 @@ public class Grid : GLib.Object
_grid[cur.row,cur.col] = 0;
_grid[match.row,match.col] = 0;
_grid[free.row,free.col] = val*2;
+ _check_target_value_reached (val*2);
free.row++;
} else if (free.row != -1) {
@@ -294,6 +306,7 @@ public class Grid : GLib.Object
_grid[cur.row,cur.col] = 0;
_grid[match.row,match.col] = 0;
_grid[free.row,free.col] = val*2;
+ _check_target_value_reached (val*2);
free.col++;
} else if (free.col != -1) {
@@ -375,6 +388,7 @@ public class Grid : GLib.Object
_grid[cur.row,cur.col] = 0;
_grid[match.row,match.col] = 0;
_grid[free.row,free.col] = val*2;
+ _check_target_value_reached (val*2);
free.col--;
} else if (free.col != _cols) {
@@ -529,6 +543,13 @@ public class Grid : GLib.Object
return ret;
}
+
+ private void _check_target_value_reached (uint val)
+ {
+ if (target_value != 0)
+ if (val == target_value)
+ target_value_reached = true;
+ }
}
public struct GridPosition
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]