HTML5 SameGame engine powered by Phaser

According to this Wikipedia page , SameGame is a tile-matching puzzle video game originally released under the name “Chain Shot!” in 1985 by Kuniaki Moribe (Morisuke). It has since been ported to numerous computer platforms and handheld devices.

Its simple game mechanic is perfect to introduce tile based matching games: SameGame is played on a rectangular field, typically initially filled with four or five kinds of blocks placed at random. By selecting a group of adjoining blocks of the same color, a player may remove them from the screen. Blocks that are no longer supported will fall down, and a column without any blocks will be trimmed away by other columns always sliding to one side (often the left). The goal of the game is to remove as many blocks from the playing field as possible.

You can Google for “SameGame” and play a ton of SameGame clones, and this is the plain engine, with no animations to keep the code as simple as possible:

Click on a tile to remove the group of tiles of the same color, there must be at least two tiles of the same color for you to remove them.

The code is very simple and although is not commented, it’s very readable. Anyway, here is a brief information about how the game works:

* Tiles are placed on stage, in this case a 8×8 board with 4 different colors

* The player selects a tile

* A flood fill algorithm is performed to see how may tiles of the same color are grouped with the selected tile

* If there’s only one tile, the move is not valid

* If there are at least two tiles, we remove them

* Tiles witouth another tile under their feet fall down

* Columns with an empty column on their left will slide to the left

* The player can select another tile

This is the source code:

Download the source code of the full project, a complete game as well as some interesting variations of SameGame will follow during next days.