[iagno] Split Player enum into its own file



commit 06f1667d32788193dac5fc30e74cb1251a32aa57
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Sep 27 21:57:47 2013 -0500

    Split Player enum into its own file
    
    Also, add a couple of convenience methods

 po/POTFILES.in   |    1 +
 po/POTFILES.skip |    1 +
 src/Makefile.am  |    3 +-
 src/game.vala    |    7 -----
 src/player.vala  |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 70 insertions(+), 8 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1fb5974..afad3ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,3 +8,4 @@ src/computer-player.vala
 src/game.vala
 src/game-view.vala
 src/iagno.vala
+src/player.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 1034037..f5ebe9b 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -3,3 +3,4 @@ src/computer-player.c
 src/game.c
 src/game-view.c
 src/iagno.c
+src/player.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 54f88e0..5088809 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,8 @@ iagno_SOURCES = \
        computer-player.vala \
        game.vala \
        game-view.vala \
-       iagno.vala
+       iagno.vala \
+       player.vala
 
 iagno_CFLAGS = \
        -DVERSION=\"$(VERSION)\" \
diff --git a/src/game.vala b/src/game.vala
index f1de703..32cb6cc 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -8,13 +8,6 @@
  * license.
  */
 
-public enum Player
-{
-    NONE,
-    LIGHT,
-    DARK
-}
-
 public class Game
 {
     /* Tiles on the board */
diff --git a/src/player.vala b/src/player.vala
new file mode 100644
index 0000000..d26f28a
--- /dev/null
+++ b/src/player.vala
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2013 Michael Catanzaro
+ *
+ * This file is part of Iagno.
+ *
+ * Iagno is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Iagno is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Iagno.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+public enum Player
+{
+    NONE,
+    LIGHT,
+    DARK;
+
+    public string to_string ()
+    {
+        switch (this)
+        {
+        case LIGHT:
+            return "L";
+        case DARK:
+            return "D";
+        default:
+            warn_if_fail (this == NONE);
+            return " ";
+        }
+    }
+
+    public static Player from_char (char c)
+        requires (c == 'L' || c == 'D' || c == ' ')
+    {
+        switch (c)
+        {
+        case 'L':
+            return LIGHT;
+        case 'D':
+            return DARK;
+        case ' ':
+            return NONE;
+        default:
+            warn_if_reached ();
+            return NONE;
+        }
+    }
+
+    public static Player flip_color (Player p)
+        requires (p == Player.LIGHT || p == Player.DARK)
+    {
+        if (p == Player.LIGHT)
+            return Player.DARK;
+        else
+            return Player.LIGHT;
+    }
+}
+


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