samples/games/stonePairs: Added missing resources, tutorial slides
authorJerome St-Louis <jerome@ecere.com>
Wed, 23 Apr 2014 08:02:05 +0000 (04:02 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 23 Apr 2014 08:04:00 +0000 (04:04 -0400)
- Also improved display of winning stones: now desaturating other stones

samples/games/stonePairs/Building a simple board game with the Ecere SDK.odp [new file with mode: 0644]
samples/games/stonePairs/game.ec [moved from samples/games/brainstonz/game.ec with 98% similarity]
samples/games/stonePairs/res/arrow.png [new file with mode: 0644]
samples/games/stonePairs/res/black.png [new file with mode: 0644]
samples/games/stonePairs/res/blackGray.png [new file with mode: 0644]
samples/games/stonePairs/res/board.jpg [new file with mode: 0644]
samples/games/stonePairs/res/remove.png [new file with mode: 0644]
samples/games/stonePairs/res/white.png [new file with mode: 0644]
samples/games/stonePairs/res/whiteGray.png [new file with mode: 0644]
samples/games/stonePairs/stonePairs.ec [moved from samples/games/brainstonz/brainstonz.ec with 81% similarity]
samples/games/stonePairs/stonePairs.epj [moved from samples/games/brainstonz/brainstonz.epj with 82% similarity]

diff --git a/samples/games/stonePairs/Building a simple board game with the Ecere SDK.odp b/samples/games/stonePairs/Building a simple board game with the Ecere SDK.odp
new file mode 100644 (file)
index 0000000..971c9cb
Binary files /dev/null and b/samples/games/stonePairs/Building a simple board game with the Ecere SDK.odp differ
similarity index 98%
rename from samples/games/brainstonz/game.ec
rename to samples/games/stonePairs/game.ec
index 3dc9447..f78832f 100644 (file)
@@ -10,7 +10,7 @@ int symbols[4][4] =
    { 2, 3, 0, 7 }
 };
 
-class BrainStonzGame
+class StonePairsGame
 {
    int movesLeft;
    movesLeft = 1;
@@ -110,7 +110,7 @@ class BrainStonzGame
    }
 }
 
-BrainStonzGame game { };
+StonePairsGame game { };
 
 class GameConnection
 {
diff --git a/samples/games/stonePairs/res/arrow.png b/samples/games/stonePairs/res/arrow.png
new file mode 100644 (file)
index 0000000..f944b76
Binary files /dev/null and b/samples/games/stonePairs/res/arrow.png differ
diff --git a/samples/games/stonePairs/res/black.png b/samples/games/stonePairs/res/black.png
new file mode 100644 (file)
index 0000000..bbdfa37
Binary files /dev/null and b/samples/games/stonePairs/res/black.png differ
diff --git a/samples/games/stonePairs/res/blackGray.png b/samples/games/stonePairs/res/blackGray.png
new file mode 100644 (file)
index 0000000..a043b95
Binary files /dev/null and b/samples/games/stonePairs/res/blackGray.png differ
diff --git a/samples/games/stonePairs/res/board.jpg b/samples/games/stonePairs/res/board.jpg
new file mode 100644 (file)
index 0000000..6bc232b
Binary files /dev/null and b/samples/games/stonePairs/res/board.jpg differ
diff --git a/samples/games/stonePairs/res/remove.png b/samples/games/stonePairs/res/remove.png
new file mode 100644 (file)
index 0000000..e7a8d17
Binary files /dev/null and b/samples/games/stonePairs/res/remove.png differ
diff --git a/samples/games/stonePairs/res/white.png b/samples/games/stonePairs/res/white.png
new file mode 100644 (file)
index 0000000..f3f8b90
Binary files /dev/null and b/samples/games/stonePairs/res/white.png differ
diff --git a/samples/games/stonePairs/res/whiteGray.png b/samples/games/stonePairs/res/whiteGray.png
new file mode 100644 (file)
index 0000000..e679f9e
Binary files /dev/null and b/samples/games/stonePairs/res/whiteGray.png differ
similarity index 81%
rename from samples/games/brainstonz/brainstonz.ec
rename to samples/games/stonePairs/stonePairs.ec
index 3b2b6e7..99ff3c4 100644 (file)
@@ -5,23 +5,24 @@ define upperLeftX = 334;
 define upperLeftY = 147;
 define spaceX = (676 - upperLeftX);
 define spaceY = (485 - upperLeftY);
-define whiteDrawer = 150;
-define blackDrawer = 1888;
+define whiteDrawer = 145;
+define blackDrawer = 1885;
 define topDrawer = 126;
+define stoneOverlap = 0.75;
 
 class MainWindow : Window
 {
    GameConnection player1 { };
    GameConnection player2 { };
 
-   text = "BrainStonz";
+   text = "Stone Pairs";
    background = black;
    borderStyle = sizable;
    hasMaximize = true;
    hasMinimize = true;
    hasClose = true;
-   state = maximized;
-   size = { w = parent.clientSize.h * 2038/1647, h = parent.clientSize.h };
+   clientSize = { 1019, 824 };
+
    hasMenuBar = true;
 
    BitmapResource boardBmp { ":board.jpg", window = this };
@@ -32,7 +33,9 @@ class MainWindow : Window
    { [
       null,
       BitmapResource { ":black.png", alphaBlend = true, window = this },
-      BitmapResource { ":white.png", alphaBlend = true, window = this }
+      BitmapResource { ":white.png", alphaBlend = true, window = this },
+      BitmapResource { ":blackGray.png", alphaBlend = true, window = this },
+      BitmapResource { ":whiteGray.png", alphaBlend = true, window = this }
    ] };
 
    menu = { };
@@ -101,6 +104,7 @@ class MainWindow : Window
 
       int x, y;
       Stone c;
+      bool draw = false;
 
       // Draw the board
       DrawBitmap(surface, boardBmp, 0,0, 1);
@@ -115,7 +119,20 @@ class MainWindow : Window
 
          for(r = 0; r < game.numStones[c]; r++)
             DrawBitmap(surface, stoneBmps[c],
-               drawerX - stone.width/2, topDrawer + r*wStone.height*2/3, 1);
+               drawerX - stone.width/2, topDrawer + (int)(r*wStone.height*stoneOverlap), 1);
+      }
+
+      if(!game.takeOut)
+      {
+         draw = true;
+         for(y = 0; draw && y < 4; y++)
+         {
+            for(x = 0; draw && x < 4; x++)
+            {
+               if(!game.stones[y][x])
+                  draw = false;
+            }
+         }
       }
 
       // Draw the stones
@@ -125,17 +142,16 @@ class MainWindow : Window
          {
             Stone stone = game.stones[y][x];
             if(stone)
+            {
+               if(game.winner || draw) stone += 2;
                DrawStone(surface, { x, y }, stone);
+            }
          }
       }
 
-      // Inform the player he can remove a stone
-      if(game.takeOut)
-         DrawBitmap(surface, removeBmp, board.width/2 - removeBmp.bitmap.width*3/2, 30, 4);
-
-      // Display a win
       if(game.winner)
       {
+         // Display winning stones only in color
          int i;
          for(i = 0; i < 4; i++)
          {
@@ -145,27 +161,36 @@ class MainWindow : Window
                if(game.stones[i][j] != game.winner)
                   break;
             if(j == 4)
-               DrawWin(surface, {0, i}, { 3, i });
+               for(j = 0; j < 4; j++)
+                  DrawStone(surface, { j, i }, game.winner);
 
             for(j = 0; j < 4; j++)
                if(game.stones[j][i] != game.winner)
                   break;
             if(j == 4)
-               DrawWin(surface, {i, 0}, { i, 3 });
+               for(j = 0; j < 4; j++)
+                  DrawStone(surface, { i, j }, game.winner);
          }
          for(i = 0; i < 4; i++)
             if(game.stones[i][i] != game.winner)
                break;
          if(i == 4)
-            DrawWin(surface, {0, 0}, { 3, 3 });
+            for(i = 0; i < 4; i++)
+               DrawStone(surface, { i, i }, game.winner);
 
          for(i = 0; i < 4; i++)
             if(game.stones[3-i][i] != game.winner)
                break;
          if(i == 4)
-            DrawWin(surface, {0, 3}, { 3, 0 });
+            for(i = 0; i < 4; i++)
+               DrawStone(surface, { i, 3-i }, game.winner);
       }
-      else
+
+      // Inform the player he can remove a stone
+      if(game.takeOut)
+         DrawBitmap(surface, removeBmp, board.width/2 - removeBmp.bitmap.width*3/2, 30, 4);
+
+      if(!game.winner && !draw)
       {
          // Display the current turn
          DrawBitmap(surface, arrowBmp,
similarity index 82%
rename from samples/games/brainstonz/brainstonz.epj
rename to samples/games/stonePairs/stonePairs.epj
index fb84c41..6b0b9e7 100644 (file)
@@ -1,10 +1,10 @@
 {
    "Version" : 0.2,
-   "ModuleName" : "brainstonz",
+   "ModuleName" : "stonePairs",
    "Options" : {
       "Warnings" : "All",
       "TargetType" : "Executable",
-      "TargetFileName" : "brainstonz",
+      "TargetFileName" : "stonePairs",
       "Libraries" : [
          "ecere"
       ]
@@ -31,7 +31,7 @@
       }
    ],
    "Files" : [
-      "brainstonz.ec",
+      "stonePairs.ec",
       "game.ec"
    ],
    "ResourcesPath" : "",
@@ -40,7 +40,8 @@
       "res/black.png",
       "res/board.jpg",
       "res/remove.png",
-      "res/smile.png",
-      "res/white.png"
+      "res/white.png",
+      "res/blackGray.png",
+      "res/whiteGray.png"
    ]
 }