Home

A complete example: The FloodIt! game

A complete example: The FloodIt! game

To complete this tutorial, here is my implementation of the FloodIt! game: floodit.scala

The game starts by drawing a grid of cells colored randomly in six colors. At the bottom, you see six buttons labeled in the same six colors. You also see an indication of the number of turns to the right of the six buttons.

Start state of FloodIt

When you press a colored button, it will change the color of the top-left grid cell and all the cells that are connected to it in the same color. For instance, after four turns you might be in this situation:

After 4 turns

If you now press the red button, the top-left cell and all the connected blue cells change to red, and the situation looks like this:

After 5 turns

Note that the turn counter has increased to five.

The goal of the game is to turn the entire grid into one single color with as few turns as possible.