Sonstiges: Developer Diary - The Creation of a 3DS/Switch Game
Michael Grönert, am 26.12.2016, Seite 15 von 20
Part 15: Pairs - Find matching cards
Today we make an exception and implement a new little game independent of GameMaster which we will build into our main game later. It is a ”Pairs” (or “Concentration”) variant, where you have to find pairs of cards. In Germany, this kind of game is mainly known under the name Memory which, belongs to the German company Ravensburger. The player has a set of face-down cards in front of themselves with each of the cards is presented twice. They flip two cards over per turn, hoping to find a matching pair. If it is a pair, the player gets one point and the cards can either be removed or left face-up and the player is allowed to choose two more cards. Should they have picked different cards, they are turned back again and the move is over. Now the next player can choose two cards - so any number of players is possible. If all pairs are found, the game is over and the player with the most found pairs has won. So the challenge in this game is to memorize the cards and their positions in order to find them later.
Title screen of the game
Motivation for independent game
Since GameMaster is an enormously extensive project which will take a lot of time to complete, it would be nice to produce something that can be completed quickly and presented in the meantime. But I had two more reasons: First, I wanted to give a friend a simple introduction to Unity. Second, this game with its pictures on the cards makes a perfect gift. For this stand-alone version, I use photos from my recent holidays in Indonesia and Singapore over Christmas 2017 and New Year's Eve 2018. For the GameMaster version of this game, however, I will have to use different pictures as these photos take up much space even in a strongly compressed state and don’t quite fit into the context.
A few found pairs
The key part of the mini game is the cards. These have two different sides and can be turned over by clicking or tapping. For this purpose, Unity offers two-dimensional surfaces such as "plains" or "quads" which can be covered with a texture. Clicking activates an animation that rotates the card 180° in within a certain period of time instead of turning it around abruptly. In addition, we need a controller object that manages everything. It lets only two cards be turned over at once, points are awarded for found pairs and other cards are turned back. Of course, the controller also has to manage much more. It initially creates the pairs of cards and puts them on a square grid in random order. It also visualizes switching the player turn and displays the scores. A little extra feature is collecting cards. There are about 150 different cards randomly selected. Each card that was once found as pair is listed in the "Collection" menu, along with the number of cards found so far and the total number of cards. Here, the pictures can be viewed in peace. Also after a pair was found, the image of the cards gets zoomed in until the user closes this view.
The collection with all found images
The pictures also need to be prepared for the game. First, they should be square but the size and quality play an important role, as well. Actually, at the beginning I spent a lot of time trying out moving pictures in the form of gifs or videos. However, I came across several problems that I would not like to explain in more detail here, especially if you want this to work on all platforms. Therefore, I decided to limit myself to normal photos. I have cropped all these photos manually because I wanted to make sure that the respective section is optimally chosen. Since I did not know how many pictures it would take in total and how much storage they would occupy compressed when I started out, I decided to put each photo in two resolutions (256x256 and 512x512) instead of having to do the work twice if necessary. I had even considered building two different variants with these different resolutions, but ultimately decided on the 512x512 pixels.
But with all the pictures I faced a new problem: The game would take a long time to load to prepare the textures. To counteract this problem, the photos are stored in an extra resource folder and are only loaded asynchronous at runtime. In other words, the game can already be started before the pictures are even ready to be displayed. Accordingly, the cards and elements in the collection only have a white surface until the respective photo has finished loading. In practice, however, this is done so quickly that the textures are already done before the cards are laid out or the collection has been opened, but this has a very positive effect on the entire loading time of the game.
Zoomed-in image from Singapore
As already mentioned, you can play “Pairs” with theoretically any number of people. For this version I also offer a two-player mode in addition to the single player. You can choose between three AI levels and a local human player. For the GameMaster version, however, I have four players planned, similar to our pioneer minigame “Gong”. The AIs are relatively simple. The weakest of them always chooses two cards at absolute random. The other two remember which cards have already been revealed and are trying to uncover pairs. If their turn begins, they first check whether a pair is already among the previously visible and reveal it. If not, they choose a random card from those that were not visible yet and uncover it. If its partner card was already visible, this one will be taken. Otherwise, another random one that was not yet visible. This means that they play perfectly from the point of view of an human but do not have information reserved for humans. In order to weaken one of the two AIs, I let them choose a wrong card with a certain probability, even if they already know the correct one - just like a person who has forgotten the exact position of one of the already visible cards.
You can take a look at the result yourself if you want. The game is available for free and without ads: For iOS, in the App Store. And for Android, in the Google Play Store and on Amazon. Until next time!
Do you prefer to read this diary in the developer's mother tongue? Then click here to read this diary entry in the original German language!