[iagno] Remove can_undo().
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Remove can_undo().
- Date: Wed, 24 Sep 2014 13:38:49 +0000 (UTC)
commit 16da7a83939ddea8e4148a29b3f8fc82981d50f6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Sep 24 07:55:01 2014 +0200
Remove can_undo().
https://bugzilla.gnome.org/show_bug.cgi?id=736934
src/game.vala | 8 +-------
src/iagno.vala | 6 +++---
src/test-iagno.vala | 18 +++++++++---------
3 files changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 5cf4fb6..41e0d96 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -28,7 +28,7 @@ public class Game : Object
/* Color to move next; Dark always plays first;
* should be dark if number_of_moves % 2 == 0 */
public Player current_color { get; private set; default = Player.DARK; }
- private int number_of_moves = 0;
+ public int number_of_moves { get; private set; default = 0; }
/* Indicate that a player should move */
public signal void move ();
@@ -313,12 +313,6 @@ public class Game : Object
* * Undo
\*/
- public bool can_undo (int count = 1)
- requires (count == 1 || count == 2)
- {
- return number_of_moves >= count;
- }
-
public void undo (int count = 1)
requires (count == 1 || count == 2)
requires (number_of_moves >= count)
diff --git a/src/iagno.vala b/src/iagno.vala
index a02652b..758c70c 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -249,12 +249,12 @@ public class Iagno : Gtk.Application
var undo_action = (SimpleAction) lookup_action ("undo-move");
if (player_one == Player.DARK || computer == null)
- undo_action.set_enabled (game.can_undo (1));
+ undo_action.set_enabled (game.number_of_moves >= 1);
else
- undo_action.set_enabled (game.can_undo (2));
+ undo_action.set_enabled (game.number_of_moves >= 2);
var new_game_action = (SimpleAction) lookup_action ("new-game");
- new_game_action.set_enabled (game.can_undo (1));
+ new_game_action.set_enabled (game.number_of_moves >= 1);
/* Translators: this is a 2 digit representation of the current score. */
dark_score_label.set_markup ("<span font_weight='bold'>"+(_("%.2d").printf
(game.n_dark_tiles))+"</span>");
diff --git a/src/test-iagno.vala b/src/test-iagno.vala
index 95e08b0..73fc4fa 100644
--- a/src/test-iagno.vala
+++ b/src/test-iagno.vala
@@ -31,31 +31,31 @@ public class TestIagno : Object
" L L L L L L L L",
" L L L L L L L L"};
Game game = new Game.from_strings (board, Player.DARK);
+ assert (game.number_of_moves == 0);
assert (game.place_tile (7, 2) > 0);
+ assert (game.number_of_moves == 1);
assert (!game.can_move (Player.LIGHT));
- assert (game.can_undo ());
game.pass ();
- assert (game.can_undo ());
+ assert (game.number_of_moves == 2);
game.undo (2);
+ assert (game.number_of_moves == 0);
assert (game.to_string ().strip () == string.joinv ("\n", board).strip ());
assert (game.place_tile (7, 2) > 0);
+ assert (game.number_of_moves == 1);
assert (!game.can_move (Player.LIGHT));
- assert (game.can_undo ());
game.undo (1);
+ assert (game.number_of_moves == 0);
assert (game.to_string ().strip () == string.joinv ("\n", board).strip ());
}
private static void test_undo_at_start ()
{
Game game = new Game ();
- assert (!game.can_undo (1));
- assert (!game.can_undo (2));
+ assert (game.number_of_moves == 0);
game.place_tile (2, 3);
- assert (game.can_undo (1));
- assert (!game.can_undo (2));
+ assert (game.number_of_moves == 1);
game.place_tile (2, 2);
- assert (game.can_undo (1));
- assert (game.can_undo (2));
+ assert (game.number_of_moves == 2);
}
private static void test_current_color_after_pass ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]