[gnome-taquin] Add a security.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Add a security.
- Date: Mon, 18 Feb 2019 14:23:28 +0000 (UTC)
commit 309cb65ed008f057cd276ea3971be642f44697d0
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Feb 18 14:58:46 2019 +0100
Add a security.
Use an infinity sign when too
much moves have been done. It
should normally never happen.
src/game-headerbar.vala | 14 ++++++++++++--
src/taquin-game.vala | 20 ++++++++++++++++----
2 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index 52eb7db..71e6b07 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -158,7 +158,7 @@ private class GameHeaderBar : BaseHeaderBar
private uint last_moves_count = 0;
internal void set_moves_count (ref uint moves_count)
{
- history_button.set_label (moves_count.to_string ());
+ history_button.set_label (get_moves_count_string (ref moves_count));
history_button.set_sensitive ((moves_count != 0) || (best_score != 0));
last_moves_count = moves_count;
}
@@ -297,9 +297,19 @@ private class GameHeaderBar : BaseHeaderBar
GLib.Menu section = new GLib.Menu ();
/* Translators: during a game that has already been finished (and possibly restarted), entry in the
menu of the moves button */
- section.append (_("Best score: %u").printf (best_score), null);
+ section.append (_("Best score: %s").printf (get_moves_count_string (ref best_score)), null);
section.freeze ();
menu.append_section (null, section);
}
+
+ private static string get_moves_count_string (ref uint moves_count)
+ {
+ string moves_count_string;
+ if (moves_count != uint.MAX)
+ moves_count_string = moves_count.to_string ();
+ else
+ moves_count_string = "∞";
+ return moves_count_string;
+ }
}
diff --git a/src/taquin-game.vala b/src/taquin-game.vala
index df12d63..599e3e6 100644
--- a/src/taquin-game.vala
+++ b/src/taquin-game.vala
@@ -188,11 +188,17 @@ private class Game : Object
int8 move_number = move_x_axis ? x_gap - x : y_gap - y;
if (undoing)
- moves_count--;
+ {
+ if (moves_count == 0)
+ assert_not_reached ();
+ if (moves_count != uint.MAX)
+ moves_count--;
+ }
else
{
add_move (/* move_x_axis, move_number,*/ x_gap, y_gap);
- moves_count++;
+ if (moves_count != uint.MAX)
+ moves_count++;
}
if (move_x_axis)
@@ -278,11 +284,17 @@ private class Game : Object
}
if (undoing)
- moves_count--;
+ {
+ if (moves_count == 0)
+ assert_not_reached ();
+ if (moves_count != uint.MAX)
+ moves_count--;
+ }
else
{
add_move (move_x_axis ? (new_coord == 0 ? -1 : size) : x, move_x_axis ? y : (new_coord == 0 ? -1
: size));
- moves_count++;
+ if (moves_count != uint.MAX)
+ moves_count++;
}
move (move_x_axis,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]