Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to make a Windows minesweeping game

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to use Python to do a Windows minesweeping game, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Minesweeping on Windows XP is the collective memory of countless post-80s / 90s. Today we will use Python to make a high-imitation version of the minesweeping game.

Forgive me for my broken hand, but mine sweeping basically never won. During the test, I secretly changed the number of mines from 99 to 50 to win.

Let's talk about my implementation logic.

First of all, how to represent mine and non-mine, the first idea is to establish a two-dimensional array to represent the whole region, 0 for non-mine and 1 for mine. Later, I thought it was wrong, and it was marked as a landmine, marked as a question mark, and a number indicating the number of mines around it. Many states, so let's just make a category:

Mine laying is very simple. Take 99 numbers at random and arrange them from top to bottom:

When we click on a grid, as long as according to the coordinates of the click, find the corresponding Mine, see what its value is, we will know whether it has stepped on the mine or not.

If you don't hit the mine, count how many mines are in the 8 surrounding positions in order to display the corresponding number.

If there is lightning around, then show the number, this is simple, but if there is no lightning around, it will show an area until there is thunder, as shown in the following picture, I only click in the middle, there is such a large area

In fact, this calculation is also easy, as long as the use of recursion, if the calculation of the surrounding mine number is 0, then recursively calculate the surrounding 8 locations around the mine number until the mine number is not zero.

Next, there is another trouble. We often press the left and right mouse buttons at the same time. If Lei is marked all at once, he will open all the boxes around him at once. If there is any wrong mark, then sorry, GAME OVER.

If it is not fully marked, there will be an effect showing a circle of unopened and marked squares around

That's all the main logic of minesweeping, and all that's left are miscellaneous incidents. Of course, these miscellaneous events are still enough for you to struggle with.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report