[four-in-a-row] Rename enum members.



commit ccdb503dad163135e2990f02bc538ce9324d9f40
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Dec 23 03:39:29 2019 +0100

    Rename enum members.

 src/four-in-a-row.vala   | 32 ++++++++++++++---------------
 src/game-board-view.vala |  8 ++++----
 src/scorebox.vala        | 52 ++++++++++++++++++++++++------------------------
 src/theme.vala           |  6 +++---
 4 files changed, 49 insertions(+), 49 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 60e5298..de10af2 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -51,7 +51,7 @@ private class FourInARow : Gtk.Application
 
     // game status
     private bool gameover = true;
-    private PlayerID player = PlayerID.PLAYER1;
+    private PlayerID player = PlayerID.NOBODY;
     private PlayerID winner = PlayerID.NOBODY;
     private PlayerID last_first_player = PlayerID.NOBODY;
     private Board game_board = new Board ();
@@ -317,17 +317,17 @@ private class FourInARow : Gtk.Application
         }
         if (one_player_game)
         {
-            player = settings.get_string ("first-player") == "computer" ? PlayerID.PLAYER2 : 
PlayerID.PLAYER1;
-            settings.set_string ("first-player", player == PlayerID.PLAYER1 ? "computer" : "human");
+            player = settings.get_string ("first-player") == "computer" ? PlayerID.OPPONENT : PlayerID.HUMAN;
+            settings.set_string ("first-player", player == PlayerID.HUMAN ? "computer" : "human");
             ai_level = (uint8) settings.get_int ("opponent");
         }
         else
         {
             switch (last_first_player)
             {
-                case PlayerID.PLAYER1: player = PlayerID.PLAYER2; break;
-                case PlayerID.PLAYER2:
-                case PlayerID.NOBODY : player = PlayerID.PLAYER1; break;
+                case PlayerID.HUMAN   : player = PlayerID.OPPONENT; break;
+                case PlayerID.OPPONENT:
+                case PlayerID.NOBODY  : player = PlayerID.HUMAN; break;
             }
             last_first_player = player;
         }
@@ -463,11 +463,11 @@ private class FourInARow : Gtk.Application
         {
             string who;
             if (gameover)
-                who = player == PLAYER1 ? theme_get_player_win (PlayerID.PLAYER1, theme_id)
-                                        : theme_get_player_win (PlayerID.PLAYER2, theme_id);
+                who = player == HUMAN ? theme_get_player_win  (PlayerID.HUMAN,    theme_id)
+                                      : theme_get_player_win  (PlayerID.OPPONENT, theme_id);
             else
-                who = player == PLAYER1 ? theme_get_player_turn (PlayerID.PLAYER1, theme_id)
-                                        : theme_get_player_turn (PlayerID.PLAYER2, theme_id);
+                who = player == HUMAN ? theme_get_player_turn (PlayerID.HUMAN,    theme_id)
+                                      : theme_get_player_turn (PlayerID.OPPONENT, theme_id);
 
             set_status_message (_(who));
         }
@@ -475,7 +475,7 @@ private class FourInARow : Gtk.Application
 
     private void swap_player ()
     {
-        player = (player == PlayerID.PLAYER1) ? PlayerID.PLAYER2 : PlayerID.PLAYER1;
+        player = (player == PlayerID.HUMAN) ? PlayerID.OPPONENT : PlayerID.HUMAN;
         move_cursor (3);
         prompt_player ();
     }
@@ -540,7 +540,7 @@ private class FourInARow : Gtk.Application
     private bool is_player_human ()
     {
         if (one_player_game)
-            return player == PlayerID.PLAYER1;
+            return player == PlayerID.HUMAN;
         else
             return true;
     }
@@ -577,7 +577,7 @@ private class FourInARow : Gtk.Application
 
     private inline void drop ()
     {
-        PlayerID tile = player == PlayerID.PLAYER1 ? PlayerID.PLAYER1 : PlayerID.PLAYER2;
+        PlayerID tile = player == PlayerID.HUMAN ? PlayerID.HUMAN : PlayerID.OPPONENT;
 
         game_board [row, column] = PlayerID.NOBODY;
         game_board_view.draw_tile (row, column);
@@ -593,7 +593,7 @@ private class FourInARow : Gtk.Application
         game_board_view.draw_tile (0, column);
 
         column = c;
-        game_board [0, c] = player == PlayerID.PLAYER1 ? PlayerID.PLAYER1 : PlayerID.PLAYER2;
+        game_board [0, c] = player == PlayerID.HUMAN ? PlayerID.HUMAN : PlayerID.OPPONENT;
 
         game_board_view.draw_tile (0, c);
     }
@@ -1111,7 +1111,7 @@ private class FourInARow : Gtk.Application
 }
 
 private enum PlayerID {
-    PLAYER1,
-    PLAYER2,
+    HUMAN,
+    OPPONENT,
     NOBODY;
 }
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index 46d3b43..e2ebe4e 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -132,15 +132,15 @@ private class GameBoardView : Gtk.DrawingArea
         if (row == 0)
             switch (tile)
             {
-                case PlayerID.PLAYER1 : os = offset [Tile.PLAYER1_CURSOR]; break;
-                case PlayerID.PLAYER2 : os = offset [Tile.PLAYER2_CURSOR]; break;
+                case PlayerID.HUMAN   : os = offset [Tile.PLAYER1_CURSOR]; break;
+                case PlayerID.OPPONENT: os = offset [Tile.PLAYER2_CURSOR]; break;
                 case PlayerID.NOBODY  : os = offset [Tile.CLEAR_CURSOR];   break;
             }
         else
             switch (tile)
             {
-                case PlayerID.PLAYER1 : os = offset [Tile.PLAYER1]; break;
-                case PlayerID.PLAYER2 : os = offset [Tile.PLAYER2]; break;
+                case PlayerID.HUMAN   : os = offset [Tile.PLAYER1]; break;
+                case PlayerID.OPPONENT: os = offset [Tile.PLAYER2]; break;
                 case PlayerID.NOBODY  : assert_not_reached ();
             }
 
diff --git a/src/scorebox.vala b/src/scorebox.vala
index cec7402..17a160e 100644
--- a/src/scorebox.vala
+++ b/src/scorebox.vala
@@ -55,25 +55,25 @@ private class Scorebox : Dialog {
         grid.add(grid2);
         grid2.column_spacing = 6;
 
-        label_name[PlayerID.PLAYER1] = new Label(null);
-        grid2.attach(label_name[PlayerID.PLAYER1], 0, 0, 1, 1);
-        label_name[PlayerID.PLAYER1].xalign = 0;
-        label_name[PlayerID.PLAYER1].yalign = 0.5f;
-
-        label_score[PlayerID.PLAYER1] = new Label(null);
-        grid2.attach(label_score[PlayerID.PLAYER1], 1, 0, 1, 1);
-        label_score[PlayerID.PLAYER1].xalign = 0;
-        label_score[PlayerID.PLAYER1].yalign = 0.5f;
-
-        label_name[PlayerID.PLAYER2] = new Label(null);
-        grid2.attach(label_name[PlayerID.PLAYER2], 0, 1, 1, 1);
-        label_name[PlayerID.PLAYER2].xalign = 0;
-        label_name[PlayerID.PLAYER2].yalign = 0.5f;
-
-        label_score[PlayerID.PLAYER2] = new Label(null);
-        grid2.attach(label_score[PlayerID.PLAYER2], 1, 1, 1, 1);
-        label_score[PlayerID.PLAYER2].set_xalign(0);
-        label_score[PlayerID.PLAYER2].set_yalign(0.5f);
+        label_name[PlayerID.HUMAN] = new Label(null);
+        grid2.attach(label_name[PlayerID.HUMAN], 0, 0, 1, 1);
+        label_name[PlayerID.HUMAN].xalign = 0;
+        label_name[PlayerID.HUMAN].yalign = 0.5f;
+
+        label_score[PlayerID.HUMAN] = new Label(null);
+        grid2.attach(label_score[PlayerID.HUMAN], 1, 0, 1, 1);
+        label_score[PlayerID.HUMAN].xalign = 0;
+        label_score[PlayerID.HUMAN].yalign = 0.5f;
+
+        label_name[PlayerID.OPPONENT] = new Label(null);
+        grid2.attach(label_name[PlayerID.OPPONENT], 0, 1, 1, 1);
+        label_name[PlayerID.OPPONENT].xalign = 0;
+        label_name[PlayerID.OPPONENT].yalign = 0.5f;
+
+        label_score[PlayerID.OPPONENT] = new Label(null);
+        grid2.attach(label_score[PlayerID.OPPONENT], 1, 1, 1, 1);
+        label_score[PlayerID.OPPONENT].set_xalign(0);
+        label_score[PlayerID.OPPONENT].set_yalign(0.5f);
 
         /* Translators: in the Scores dialog, label of the line where is indicated the number of tie games */
         label_name[PlayerID.NOBODY] = new Label(_("Drawn:"));
@@ -95,15 +95,15 @@ private class Scorebox : Dialog {
      */
     internal void update(uint[] scores, bool one_player_game) {
         if (one_player_game) {
-            if (scores[PlayerID.PLAYER1] >= scores[PlayerID.PLAYER2]) {
+            if (scores[PlayerID.HUMAN] >= scores[PlayerID.OPPONENT]) {
                 /* Translators: in the Scores dialog, label of the line where is indicated the number of 
games won by the human player */
                 label_name[0].set_text(_("You:"));
 
                 /* Translators: in the Scores dialog, label of the line where is indicated the number of 
games won by the computer player */
                 label_name[1].set_text(_("Me:"));
 
-                label_score[0].label = scores[PlayerID.PLAYER1].to_string();
-                label_score[1].label = scores[PlayerID.PLAYER2].to_string();
+                label_score[0].label = scores[PlayerID.HUMAN].to_string();
+                label_score[1].label = scores[PlayerID.OPPONENT].to_string();
             } else {
                 /* Translators: in the Scores dialog, label of the line where is indicated the number of 
games won by the computer player */
                 label_name[0].set_text(_("Me:"));
@@ -115,11 +115,11 @@ private class Scorebox : Dialog {
                 label_score[1].label = scores[0].to_string();
             }
         } else {
-            label_name[0].label = theme_get_player(PlayerID.PLAYER1, (uint8) theme_id);    // FIXME missing 
":" at end
-            label_name[1].label = theme_get_player(PlayerID.PLAYER2, (uint8) theme_id);    // idem
+            label_name[0].label = theme_get_player(PlayerID.HUMAN, (uint8) theme_id);    // FIXME missing 
":" at end
+            label_name[1].label = theme_get_player(PlayerID.OPPONENT, (uint8) theme_id);    // idem
 
-            label_score[PlayerID.PLAYER1].label = scores[PlayerID.PLAYER1].to_string();
-            label_score[PlayerID.PLAYER2].label = scores[PlayerID.PLAYER2].to_string();
+            label_score[PlayerID.HUMAN].label = scores[PlayerID.HUMAN].to_string();
+            label_score[PlayerID.OPPONENT].label = scores[PlayerID.OPPONENT].to_string();
         }
         label_score[PlayerID.NOBODY].label  = scores[PlayerID.NOBODY].to_string();
 
diff --git a/src/theme.vala b/src/theme.vala
index 84dc3e1..7e8c3f0 100644
--- a/src/theme.vala
+++ b/src/theme.vala
@@ -46,7 +46,7 @@ private static string theme_get_title (uint8 id)
 
 private static string theme_get_player_turn (PlayerID who, uint8 theme_id)
 {
-    if (who == PlayerID.PLAYER1)
+    if (who == PlayerID.HUMAN)
         return theme [theme_id].player1_turn;
     else
         return theme [theme_id].player2_turn;
@@ -54,7 +54,7 @@ private static string theme_get_player_turn (PlayerID who, uint8 theme_id)
 
 private static string theme_get_player_win (PlayerID who, uint8 theme_id)
 {
-    if (who == PlayerID.PLAYER1)
+    if (who == PlayerID.HUMAN)
         return theme [theme_id].player1_win;
     else
         return theme [theme_id].player2_win;
@@ -62,7 +62,7 @@ private static string theme_get_player_win (PlayerID who, uint8 theme_id)
 
 private static string theme_get_player (PlayerID who, uint8 theme_id)
 {
-    if (who == PlayerID.PLAYER1)
+    if (who == PlayerID.HUMAN)
         return theme [theme_id].player1;
     else
         return theme [theme_id].player2;


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