Example: Mahjongg Game
Product: CODESYS Visualization
The Mahjongg.project
example shows the "Mahjongg" game which is programmed with CODESYS.
![]() |
Description
Find pairs of symbols. When you select pairs, they are removed. Challenge CODESYS and try to remove more tiles than CODESYS. CODESYS plays a very simple strategy, but is hard to beat.
At the beginning, the game is started with a field of 144 tiles with 36 different symbols. A tile is considered to be open when it can be moved either to the left or to the right without touching other tiles. The goal is to match open pairs of identical tiles and remove them from the board so that the tiles underneath are exposed. The game is finished when all pairs of tiles have been removed from the board or when there are no exposed pairs remaining.
Additional information
SelectableTile
: This function checks if the requirements mentioned above are fulfilled.SetCursor
: Creation of the frame of the currently selected tilePlayMahjongg
: Implementation of the main logicGetNumOfPairs
: Calculation of the number of currently available pairsCoDeSysPlays
: CODESYS tries three different strategies and chooses the one that leaves the fewest remaining tiles.Visualization
: Challenge CODESYS to play the game. CODESYS tells the user his best game. Then the user can try to beat CODESYS.Image Pool
: Storage of images within the project. The images are called in the visualization via their ID.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.14.0 or higher) |
Runtime system | CODESYS Control Win (version 3.5.14.0) |
Add-on components | - |
Note
DOWNLOAD Project