Memory Game


This tutorial introduces the basics of programming GUIs in Bloc. We will build a Memory game with separate model and view objects, using announcements to propagate GUI events to the model.


In a memory game players need to find pairs of similar cards. In each round a player turns over two cards at a time. If the two cards show the same symbol they are removed and the player gets a point. If not, they are both flipped.

The following live example shows the game after the first selection of two cards. Face-down cards are represented with a cross and flipped cards with their number:

The following example shows the same game after a couple of rounds. While this game can be played by multiple players, in this tutorial we will build a game with just one player:

Please note that the live examples are from an existing complete implementation called GtMemoryGame Object subclass: #GtMemoryGame instanceVariableNames: 'availableCards chosenCards' classVariableNames: '' package: 'GToolkit-Demo-Memory-Model' . We will, however, build a new implementation from scratch.

First, we implement the game model: Implementing the Memory Game model