A simple turn based game of getting 5 in a row on a board of 9 x 9 (81) boxes. Each player play on her own device. One person start of the game by inviting, the other then join. Then it’s on the way.
- The board is a Repeating Group fixed with 9 by 9 cells of thing Box. A box holds only an ID (to get sorted correctly) and which player is owning the box. Each Box thing is pre-created and only changed in the game.
- The hidden group Game holds the thing Game with all game settings (it also shows some data used to debug).
- Both player’s clients share the same Boxes and Game things.
- There is (deliberately) no logging in. Still I use the User to store user data during the game.
- Since the players are on different clients there is a small special handling when the game is over (won, not canceled).
The Fun Tech
There are two slightly more interesting concepts in the game:
- Highlighting the boxes the user is allowed to choose. See workflow folder Highlight. Data is stored in states in element Board. First the x and y position of the box is calculated. Then each of the 8 boxes surrounding the selected box is checked if it should be highlighted for next selection (by the other player). If the box is empty then it’s Owner is changed to 0 indicating getting highlighted.
- Checking if the current selected box gave the current player 5 in a row (winning). See workflow folder InRow. The workflow structure is based on setting delta values to work from the selected box’s x and y position. This makes the workflows reusable as they are parameterised. They are numbered; 0 = master workflow, 1-4 = one for each direction to check in, 9 = commonly used by the in 1-4. The real fun happens in 9.InRowDoCheck and 9.InRowGetNextID.
Thoughts of extensions
- Many games to be live at the same time. Select opponent by random or a friend list. Save scores (shortest time, fewest markers placed…)
- More than 2 players per game.
- Allow dynamic number of tiles in a row.