[iagno] game: add flip_current_color utility method



commit 3e15b4a1bc9da1fb8a54e3c121ccd749eebc4b71
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Sep 15 22:36:22 2013 -0500

    game: add flip_current_color utility method

 src/game.vala |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 2c58185..f1de703 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -170,11 +170,7 @@ public class Game
         if (n_tiles == 0)
             return 0;
 
-        /* Move to the next player */
-        if (current_color == Player.LIGHT)
-            current_color = Player.DARK;
-        else
-            current_color = Player.LIGHT;
+        flip_current_color ();
 
         if (is_complete)
             complete ();
@@ -188,12 +184,7 @@ public class Game
     {
         undo_history[undo_index] = 0;
         undo_index++;
-
-        if (current_color == Player.LIGHT)
-            current_color = Player.DARK;
-        else
-            current_color = Player.LIGHT;
-
+        flip_current_color ();
         move ();
     }
 
@@ -298,10 +289,7 @@ public class Game
             }
 
             /* Previous player to move again */
-            if (current_color == Player.LIGHT)
-                current_color = Player.DARK;
-            else
-                current_color = Player.LIGHT;
+            flip_current_color ();
         }
 
         move ();
@@ -322,4 +310,12 @@ public class Game
         tiles[x, y] = color;
         square_changed (x, y);
     }
+
+    private void flip_current_color ()
+    {
+        if (current_color == Player.LIGHT)
+            current_color = Player.DARK;
+        else
+            current_color = Player.LIGHT;
+    }
 }


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