[gnome-nibbles] Stop countdown if new game button is pressed
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Stop countdown if new game button is pressed
- Date: Mon, 26 Oct 2015 00:19:15 +0000 (UTC)
commit ef85d4f1cadcb41d77fb97f1baba04ffe3e06ca1
Author: Iulian Radu <iulian radu67 gmail com>
Date: Tue Aug 11 15:45:18 2015 +0300
Stop countdown if new game button is pressed
src/gnome-nibbles.vala | 9 ++++++++-
src/nibbles-game.vala | 3 +++
src/worm.vala | 2 ++
3 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index f3a1faa..2a85713 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -52,6 +52,7 @@ public class Nibbles : Gtk.Application
private NibblesGame? game = null;
private const int COUNTDOWN_TIME = 3;
+ private uint countdown_id = 0;
private const ActionEntry action_entries[] =
{
@@ -290,7 +291,7 @@ public class Nibbles : Gtk.Application
var seconds = COUNTDOWN_TIME;
view.name_labels.show ();
- Timeout.add (1000, () => {
+ countdown_id = Timeout.add (1000, () => {
countdown.set_label (seconds.to_string ());
if (seconds == 0)
{
@@ -329,6 +330,12 @@ public class Nibbles : Gtk.Application
private void show_new_game_screen_cb ()
{
+ if (countdown_id != 0)
+ {
+ Source.remove (countdown_id);
+ countdown_id = 0;
+ }
+
if (game.is_running)
game.stop ();
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 15f580a..13dd8ba 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -245,6 +245,9 @@ public class NibblesGame : Object
if (worm.is_stopped)
continue;
+ if (worm.list.is_empty)
+ continue;
+
foreach (var other_worm in worms)
{
if (worm.will_collide_with_head (other_worm)
diff --git a/src/worm.vala b/src/worm.vala
index 0fba877..5f9b375 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -231,6 +231,8 @@ public class Worm : Object
list.clear ();
list.add (starting_position);
+ added ();
+
direction = starting_direction;
change = 0;
spawn (walls);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]