Sliding puzzler
Sliding puzzles with Pygame and Python
PYTHON
Flex your coding muscles with Calvin Robinson, who reveals how to create a retro sliding puzzle game in Python.
Credit: https://inventwithpython.com/pygame/chapter4.html
OUR EXPERT
Calvin Robinson is a former assistant principal and computer science teacher. He has a degree in computer game design and coding.
For this game-coding outing we’re taking a look at implementing a classic sliding tile puzzle game, also known as the sliding block game. Usually a two dimensional video game based on a retro board game where tiles are placed on a block in a mixed fashion, the player has to sort the tiles into an order. This may be words, pictures or numbers. The board contains one blank space, enabling the player to move one tile at a time. Despite looking so simple, they can take quite a while to complete.
We’re looking at the source code by Al Sweigart reproduced with permission and available from https:// inventwithpython.com/pygame/chapter4.htmlthis version of the sliding puzzle consists of 16 spaces in a four by four grid, including one blank and 15 sequential numbers; it’s probably the most common variant of sliding tiles games. Our player will have the ability to click tiles, and provided there’s an empty space next to said tile, it will shift up, down, left or right into the empty space. At the end of the game, in order to win, the player must have one to 15 tiles sorted in order.