Use Python to develop the same mobile game for mobile phones: happy to eliminate music

The composition of Xiaoxiaole mainly includes three parts: the main body of the game, the scorer, and the timer. Let's take a look at the specific implementation.

Define some constants, such as: window width and height, number of grid rows and columns, etc. The code is as follows:

image

Then create a main window, the code is as follows:

image

Take a look at the effect:

image

Then draw an 8 x 8 grid in the window, the code is as follows:

image

Take a look at the effect:

image

Then randomly put various puzzle pieces in the grid, the code is as follows:

image

Take a look at the effect:

image


Interested students can follow the editor and apply for QQ group: 721195303 to receive this software.


Then add the scorer and timer, the code is as follows:

image

Take a look at the effect:

image

When the set game time runs out, we can generate some prompt messages, the code is as follows:

image

image

Take a look at the effect:

image

After talking about the related parts of the game graphical interface, let's look at the main processing logic of the game.

We use the mouse to manipulate the puzzle pieces, so the program needs to check whether the puzzle pieces are selected. The code is implemented as follows:

image

We need to exchange the positions of the puzzle pieces selected continuously by the mouse. The code is implemented as follows:

image

image

Every time we exchange puzzle pieces, we need to judge whether there are three or more puzzle pieces in a row. The code is implemented as follows:

image

When three or more puzzle pieces appear, these puzzle pieces need to be eliminated. The code is implemented as follows:

image

After eliminating the matching puzzle pieces, we also need to randomly generate new puzzle pieces. The code implementation is as follows:

image

image

Then repeat this process until the game time is exhausted and the game is over.

Finally, let's take a look at the game effect dynamically.

image

In this article, we use Python to implement a simple puzzle game. Those who are interested can further expand the game, such as adding levels.

I still want to recommend the Python learning group I built myself : 721195303 , all of whom are learning Python. If you want to learn or are learning Python, you are welcome to join. Everyone is a software development party and share dry goods from time to time (only Python software development related), including a copy of the latest Python advanced materials and zero-based teaching compiled by myself in 2021. Welcome friends who are in advanced and interested in Python to join!
 

Guess you like

Origin blog.csdn.net/aaahtml/article/details/113241250