Thursday, May 13, 2010

Simple logical board game in FileMaker

In this article I will show you a simple logical board game I created in FileMaker.

It's actually quite simple to implement, so I think beginners will like to investigate this unlocked solution and create their owns based on it.

The game has 4x4 cells, filled with numbers. There is an empty one which is the "gap".
You can only move the cells that are next to the gap.
(3, 15 and 9 can be moved in the picture above)

The goal is to reorder the numbers, so that they are in order, and the gap is in the lower right corner:
The board itself is a repeating field (16 repetitions), the clicking is done by an OnObjectEnter trigger attached to it (So it needs FM10- but can be modified to be FM8+ compatible by creating hidden buttons behind the repetitions).

After the click, we check if it is legal to move that piece (this is done by the "Move" script, the script parameter is the current repetition number).
If it's legal, we change the empty(gap) repetition with the clicked one, and store the empty cell's repetition number in a global variable ($$emptypiece).

After every legal movement we check if the user won the game (CheckWin script - It is just checking the repetitions with a loop).

Shuffling is done by imitating clicking at a random cell many times (500). This is important, because if we just initialized the repeating field with a random order, you may not be able to solve the game (!).

So shuffling with valid movements make sure the shuffled game can be solved.

The rest of the methods are easy to understand, check it out, you will see what they do exactly.

This is a FM10+ demo, which you can download from here . (right click- save as)

My other FileMaker based games (unlocked) can be found here:


Feel free to contact me if you need further information!

UPDATE:

I really got addicted to this :) So I modified it a little. Now it has colors, with conditional formatting (for the white gap). I also added keyboard navigation + a movement count to track our progress :)


Keyboard navigation is done by a Layout trigger (FM10+ - KeyboardMovement Script), colors are simple formatting (fill, but added a conditional formatting for the gap - white). Movement count is a simple new Number field.

So here it is, second version, you can download from here.


The material on this document is offered as is. There is no representation or warranty, expressed or implied, nor does any other contributor to this post. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.