[iagno] Add cancel_pending_computer_moves utility methods



commit bdbacea0c73172ce1796c6c1a257d7014f273e22
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Sep 28 19:11:28 2013 -0500

    Add cancel_pending_computer_moves utility methods
    
    Also, properly use it at the start of computer_move_cb
    
    This should avoid the situation where computer_move_cb gets called
    multiple times in succession.

 src/iagno.vala |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/src/iagno.vala b/src/iagno.vala
index de51d8c..8a58f1f 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -205,12 +205,7 @@ public class Iagno : Gtk.Application
 
     private void start_game ()
     {
-        /* Cancel any pending computer moves */
-        if (computer_timer != 0)
-        {
-            Source.remove (computer_timer);
-            computer_timer = 0;
-        }
+        cancel_pending_computer_moves ();
 
         if (game != null)
             SignalHandler.disconnect_by_func (game, null, this);
@@ -268,12 +263,7 @@ public class Iagno : Gtk.Application
 
     private void undo_move_cb ()
     {
-        /* Cancel any pending computer moves */
-        if (computer_timer != 0)
-        {
-            Source.remove (computer_timer);
-            computer_timer = 0;
-        }
+        cancel_pending_computer_moves ();
 
         /* Undo once if the human player just moved, otherwise undo both moves */
         if ((game.current_color == Player.DARK && dark_computer != null) ||
@@ -359,10 +349,7 @@ public class Iagno : Gtk.Application
 
     private bool computer_move_cb ()
     {
-        /* set computer_timer to 0 *before* calling move() since that will
-         * call game_move_cb and possibly create a new timer.
-         */
-        computer_timer = 0;
+        cancel_pending_computer_moves ();
         if (game.current_color == Player.LIGHT)
             light_computer.move ();
         else
@@ -370,6 +357,15 @@ public class Iagno : Gtk.Application
         return false;
     }
 
+    private void cancel_pending_computer_moves ()
+    {
+        if (computer_timer != 0)
+        {
+            Source.remove (computer_timer);
+            computer_timer = 0;
+        }
+    }
+
     private void game_complete_cb ()
     {
         update_ui ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]