Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make Mini Game with python

Shulou Source: shulou.com Published: 2022-06-01 20:49:12 10月01日 Update

This article mainly introduces the relevant knowledge of "how to use python to make Mini Game". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "how to use python to make Mini Game" can help you solve the problem.

Development tools

Python version: 3.6.4

Related modules:

Pygame module

And some modules that come with Python.

Environment building

Install Python and add it to the environment variable, and pip installs the relevant modules you need.

Introduction of principle

Game introduction:

The image is divided into m × n rectangular blocks, and the rectangular blocks in the lower right corner of the image are replaced with blank blocks, and these rectangular blocks are randomly placed into the shape of the original image. The goal of the game is to restore the randomly placed image to the original image by moving the non-blank block, and it is stipulated that the movement operation only exists when the non-blank block is moved to the blank block.

For example, the following figure shows:

Step by step:

Step1: the initial interface of the game

Since it's a game, there has to be an initial interface, right?

OK, let's first write a game initial interface:

The effect goes like this:

According to the player's own level, you can choose different difficulty jigsaw puzzles.

Step2: define mobile operation

The purpose of defining a mobile operation is to move a jigsaw puzzle (like a nonsense tweet), which is very simple to implement:

Step3: main interface of the game

OK, with the front groundwork, we can begin to implement our main game interface.

First of all, we need to disrupt the puzzle, but random disruption is likely to cause the puzzle to be unsolvable, so we randomly move the puzzle to achieve the effect of disrupting the puzzle, which is the main reason why we define the movement operation of the puzzle first:

Initialize the main interface of the game:

Finally, the functions of display refresh and event response of the main interface are realized.

Step4: game end interface

When the player completes the puzzle, the game end interface needs to be displayed, which is similar to the initial interface of the game, and it is relatively easy to implement:

This is the end of the introduction on "how to make Mini Game with python". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Interface mobile module blank Mini Game production image knowledge rectangle different original picture effect player environment industry utility event content function reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia OPPO Reno Shulou Technology Redmi