[gnome-chess] Chess clock should start after the first move
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Chess clock should start after the first move
- Date: Wed, 22 May 2013 20:23:55 +0000 (UTC)
commit c49284e494b15e3f790bc11d300f24c5fc9075fa
Author: Michael Catanzaro <mike catanzaro gmail com>
Date: Tue May 21 18:55:28 2013 -0500
Chess clock should start after the first move
White should have unlimited time for his first move.
src/chess-clock.vala | 20 ++++++++++++++------
src/chess-game.vala | 1 -
2 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/src/chess-clock.vala b/src/chess-clock.vala
index d782232..ba3c76f 100644
--- a/src/chess-clock.vala
+++ b/src/chess-clock.vala
@@ -16,7 +16,9 @@ public class ChessClock : Object
{
get
{
- if (active_color == Color.WHITE)
+ if (timer == null)
+ return 0;
+ else if (active_color == Color.WHITE)
return _white_used + (uint) (timer.elapsed () * 1000);
else
return _white_used;
@@ -33,7 +35,9 @@ public class ChessClock : Object
{
get
{
- if (active_color == Color.WHITE)
+ if (timer == null)
+ return 0;
+ else if (active_color == Color.WHITE)
return _black_used;
else
return _black_used + (uint) (timer.elapsed () * 1000);
@@ -60,7 +64,7 @@ public class ChessClock : Object
}
}
- private Timer timer;
+ private Timer? timer;
private uint expire_timeout = 0;
private uint tick_timeout = 0;
@@ -73,7 +77,6 @@ public class ChessClock : Object
_black_duration = black_duration * 1000;
_white_used = white_used;
_black_used = black_used;
- timer = new Timer ();
}
private bool is_started
@@ -86,8 +89,13 @@ public class ChessClock : Object
if (is_started)
return;
- /* Start stopwatch */
- timer.start ();
+ if (timer == null)
+ {
+ /* Starts automatically */
+ timer = new Timer ();
+ }
+ else
+ timer.start ();
/* Notify when this timer has expired */
if (active_color == Color.WHITE)
diff --git a/src/chess-game.vala b/src/chess-game.vala
index cbbbddd..e62aeb3 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1412,7 +1412,6 @@ public class ChessGame
{
_clock.expired.connect (clock_expired_cb);
_clock.active_color = current_player.color;
- _clock.start ();
}
started ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]