extras; samples: Fixed warnings
[sdk] / samples / games / cornerBlocks / cornerBlocks.ec
index 4cc635d..01f5f36 100644 (file)
@@ -7,8 +7,7 @@ public enum PlayerColor : byte
    blue, yellow, red, green;
    property CornerBlocksColor
    {
-      // TOFIX: get { return (CornerBlocksColor)((int)this+1); }
-      get { return (CornerBlocksColor)*(int *)&this+1; }
+      get { return (CornerBlocksColor)((int)this+1); }
    }
 };
 
@@ -95,7 +94,7 @@ Piece pieces[numPieces] =
          1,
          1
       }
-   }
+   },
    {
       2,3,
       {
@@ -248,8 +247,7 @@ struct CornerBlocksGameState
       PlayerColor p;
       int i;
 
-      // TOFIX: for(p = 0; p < PlayerColor::enumSize; p++)
-      for(p = blue; p <= green; p++)
+      for(p = 0; p < PlayerColor::enumSize; p++)
       {
          for(i = 0; i < numPieces; i++)
             playerPieces[p][i] = 1;
@@ -332,11 +330,11 @@ struct CornerBlocksGameState
             {
                for(x = 0; x < boardSize && !validMove; x++)
                {
-                  int flip;
+                  bool flip;
                   int direction;
                   for(direction = 0; direction < 4 && !validMove; direction++)
                   {
-                     for(flip = 0; flip <=1 && !validMove; flip++)
+                     for(flip = 0; flip <= 1 && !validMove; flip++)
                      {
                         if(ValidMove(playerColor, p, direction, flip, x, y))
                            result = validMove = true;
@@ -508,18 +506,19 @@ class CornerBlocks : Window
                         {
                            for(x = 0; x < boardSize && !validMove; x++)
                            {
-                              int flip;
+                              bool flip;
                               int direction;
                               for(direction = 0; direction < 4 && !validMove; direction++)
                               {
-                                 for(flip = 0; flip <=1 && !validMove; flip++)
+                                 for(flip = 0; flip <= 1 && !validMove; flip++)
                                  {
                                     if(gameState.ValidMove(colorPlayed, p, direction, flip, x, y))
                                     {
                                        bool result;
                                        gotMove = false;
                                        result = server.PlayPiece(p, direction, flip, x, y);
-                                       validMove = true;
+                                       if(result)
+                                          validMove = true;
                                     }
                                  }
                               }
@@ -678,7 +677,6 @@ class CornerBlocks : Window
          {
             if(gameStarted && colorPlayed == gameState.colorTurn)
             {
-               Piece * piece = &pieces[selectedPiece];
                if(gameState.ValidMove(gameState.colorTurn, selectedPiece, direction, flip, boardPos.x, boardPos.y))
                   server.PlayPiece(selectedPiece, direction, flip, boardPos.x, boardPos.y);
             }
@@ -736,7 +734,6 @@ class CornerBlocks : Window
       {
          Piece * piece = &pieces[selectedPiece];
          int mx = drag.x - offset.x, my = drag.y - offset.y;
-         int rx, ry;
          int x = squareDragged.x, y = squareDragged.y;
          int w,h;
          bool isDown = key == wheelDown || key == right || key == down;
@@ -1059,7 +1056,7 @@ class CornerBlocks : Window
       log.inactive = bool::true;
       visible = false;
 
-      bool ProcessCommand(char * command)
+      bool ProcessCommand(const char * command)
       {
          cornerBlocks.server.SendMessage(command);
          return false;
@@ -1098,7 +1095,7 @@ class CornerBlocksScores : Window
    void OnRedraw(Surface surface)
    {
       PlayerColor p;
-      char * s;
+      const char * s;
       int len;
       char temp[256];
       int grandTotals[4];
@@ -1121,8 +1118,7 @@ class CornerBlocksScores : Window
 
       for(p = blue; p <= green; p++)
       {
-         // TOFIX: bug here, why is -1 required?
-         int x = 80 + (p-1) * 120;
+         int x = 80 + p * 120;
          surface.foreground = colors[1][p];
          /* // GCC internal compiler error with -O2, MinGW GCC 4.4.0
          s = (state->numPlayers == 3 && p == green) ? "* Green *" : cornerBlocks.playerNames[p];
@@ -1162,10 +1158,9 @@ class CornerBlocksScores : Window
          if((state->numPlayers == 2 && p <= yellow) ||
             (state->numPlayers == 1 && p == blue))
          {
-            // TOFIX: Annoying +2 conversion issue
             if(state->numPlayers == 2)
                grandTotals[p] = state->scores[p] + state->bonus[p] +
-                                state->scores[p+red /*2*/] + state->bonus[p+red /*2*/];
+                                state->scores[p+2] + state->bonus[p+2];
             else
                grandTotals[p] = state->scores[0] + state->bonus[0] +
                                 state->scores[1] + state->bonus[1] +
@@ -1213,7 +1208,7 @@ class CornerBlocksScores : Window
          {
             for(c = 0; c < numTies; c++)
             {
-               strcat(string, cornerBlocks.playerNames[c]);
+               strcat(string, cornerBlocks.playerNames[ties[c]]);
                if(c < numTies-2)
                   strcat(string, ", ");
                else if(c < numTies-1)
@@ -1401,7 +1396,6 @@ class CommunicationPanel : Window
 
                void GameStarted(GameInfo gameInfo)
                {
-                  int x,y;
                   int c, np = 0;
 
                   cornerBlocks.gameState.numPlayers = gameInfo.numPlayers;
@@ -1434,8 +1428,6 @@ class CommunicationPanel : Window
 
                void GameEnded()
                {
-                  int c;
-
                   panel.ListPlayers();
                   cornerBlocks.gameStarted = false;
                   cornerBlocks.btnPass.visible = false;
@@ -1509,15 +1501,15 @@ class CommunicationPanel : Window
                   }
                }
 
-               void NotifyMessage(String name, String msg)
+               void NotifyMessage(const String name, const String msg)
                {
                   EditBox log = cornerBlocks.chat.log;
-                  char * format = (log.numLines > 1 || log.line.count) ?
+                  const char * format = (log.numLines > 1 || log.line.count) ?
                      "\n%s: %s" : "%s: %s";
                   int len = strlen(msg);
                   // Avoid buffer overflow...
                   if(len >= MAX_F_STRING-100)
-                     msg[MAX_F_STRING-100] = 0;
+                     ((char *)msg)[MAX_F_STRING-100] = 0;
                   cornerBlocks.chat.Log(format, name, msg);
                }
             };