PyQt mining mine Game Study Notes (1), pyqt Study Notes

Source: Internet
Author: User

PyQt mining mine Game Study Notes (1), pyqt Study Notes

Want to learn PyQt. Start with the analysis and learning programming example according to the usual practice.

I found a source code for "mining mines" from the Internet, unloaded eight blocks, and analyzed them carefully to learn something.

There are bugs in the original program. For example, there is no bottom line in the "checker". After all mines are dug up, the program does not respond and won't be sure to win.

I have removed it and it can run properly.

The program source code can be downloaded here

All the modifications are made in game_scene.py. There are two parts in total:

First, in the function checkWin (), the original article is:

if ((self.mine_map == self.flag_map).all() and            (self.mine_map != self.open_map).all()):            self.win()

Now changed:
if (self.mine_map != self.open_map).all():            self.win()

After modification, the program can automatically and correctly determine the victory.

Second, in the paintEvent () function, the original article is:

for i in range(y+1):            p.drawLine(mx, my+i*sy, mx+x*sx, my+i*sy)

Add the following sentence:
p.drawLine(mx, my+i*sy-1, mx+x*sx, my+i*sy-1)

You can now draw the bottom of the Board.


Mining Game Design

I once wrote a mine clearance, but I should not use the mouse hardware parameters. I use the keyboard to input coordinates for each step.
Let's talk about the process.
1. First initialization: Create a 21*21 array, add a wall to the outermost side, enter-1, and then randomly place 10 mines.
2. Click the next part to focus on it!
Category (1). If it's a point to mine-> game over...
Classification (2), point to the number (there is a ray next to), is to judge the four sides of the grid there are several Ray, show
Classification (3). There are no mines around. Dynamic Planning is used here. It is difficult to extend it until it is surrounded by numbers (including-1 on the wall ).
3. It's easy to judge victory. Just keep recording the remaining mines.

Advanced Mining skills

When starting from the corner, half is luck, and then look at the numbers next to it, it indicates the number of mines around it. It looks for their focal points in the corner and determines whether there are mines. If so, mark them with flag and then match again, check whether there are overlapping locations and gradually expand outward. In particular, when there is a number 1 around and there is a connection between the places you have opened, all the surrounding areas are safe areas, so you can safely open the areas around them, but when you encounter 4 or 5, you should think slowly like skin, remember not to be in a hurry. It tests your mind. At the end of the day, it will give you a beautiful smile and a very high heart !! 2: click the mouse to clear the thunder in the area. When you press it, if a number is displayed, it indicates the number of thunder in the 9 sides around the center. If it is a thunder, it will show all mine clearance is over. When you are sure this side is mine, right-click the side and make a small red flag on it. When you are depressed, right-click the side and make a question mark on it twice to help you. confirm that this game is a trick to test people's reasoning and mathematical abilities, you can press the two keys together. for example, if you click "1" and a flag is inserted around you, you can press the two keys together on "1" and all the other keys will be opened. 3: Primary: left-click all. Intermediate: use the left button as much as possible (that is, use less right click to mine ). Advanced: left-click, right-click, and right-click. You must have a good mouse and exercise more. The brain must be quickly transferred, and the hand must be connected to the brain quickly. When the brain reaches an open area, the level of the thunder location can be determined immediately, that is, "conditioned reflection ". For "121" and other skillful areas, pay more attention to them at ordinary times. Sometimes you can just stop and think about it (to speed up scanning in the future). You should start from here when you start or don't guess. You have to guess the minimum probability of an error when you have no way to start. For example, you can use left-click to guess the vicinity of "1", right-click to guess the vicinity of "6, 7", and combine to guess. In short, mine clearance is a seemingly simple game with many reasons. You must think more and play more. My score is 2 seconds for beginners, 26 seconds for intermediate users, and 89 seconds for advanced users. It is important to improve your performance, but luck is the key. It's luck! You only need to play more, and you can do it once or twice (that is, 1 second ). Intermediate or lucky, there are a lot of thunder together (almost 20 thunder do not use right-click ). Advanced ...... It's just luck. It's just right. It is important to improve your performance, but luck is the key. In addition, there is a video of foreign experts in mine clearance, the first 1 second, the intermediate 10 seconds, the advanced 44 seconds, self-shows. However, his advanced manual work is too fast, so I naturally think of something like "variable speed gear. I want to write more details. I mainly want to write some fixed combination and probability estimation techniques. Or, first, you should leave the left button to open a blank screen, then press the mouse around the edge position and press the key together. If there is only one ray in the eight grids around the square you press, the ray will be automatically pulled out, which is easy, and then you can perform more exercises. It is easy to adjust the time. Enter the game, click a grid, and immediately click the "show desktop" icon on the edge of the bar. Then, the game is minimized, cheating method with fixed time in 1 second: (applicable to windows xp) 1. open the mine clearance, type xyzzy and press Enter Shift. There will be a small pixel dot in the upper left corner of the screen. When your mouse is hovering over the cell, there will be a bright spot if there is a ray in the cell :), remember, you must at least open a grid before you can see it. (Why? After a grid is clicked, the program determines the distribution of all mines. Why is this done, because it hopes that the first grid of the user will never be Ray?) 2. stop the timer (two methods): 1) when playing, use the window key + D to minimize all the windows, and then immediately click the mouse to restore the mine clearing window, and then click a grid that will not explode, now let's take a look? The timer has stopped. 2) The timer stops when the mouse clicks on the smiling face and does not move. You can move the mouse away from the smiling face and then release the left button. The game will not start again. Of course, the timer will continue. What is the purpose of this question? Then, you can press it to stop the timer, and then think carefully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.