Use python programming to make your own game "plug-in"!

Introduction to Python and Application Areas

insert image description here

Python is an interpreted scripting language that can be used in the following areas:

  • Web and Internet Development
  • Scientific Computing and Statistics
  • artificial intelligence
  • educate
  • Desktop Interface Development
  • software development
  • backend development
  • Web Crawler

Today, I will tell you how fun programming is with a small game and a small piece of code.

Good programming can not only improve work efficiency, but also make playing games easier. Some people would think, plug-in? Haha, let’s say that for the time being, of course my main purpose is to let everyone understand the benefits of programming, not how to cheat in games.

Closer to home, the Tower of Hanoi game, I don’t know how many people have an impression of it, it is a particularly interesting game, there is also a magical story about the Tower of Hanoi, friends who are interested can search for it. Briefly talk about the rules of the Tower of Hanoi game.

insert image description here

The picture above is a simple Tower of Hanoi game. There are three pillars ABC, and there are 3 layers of disks on the A pillar (for example, find a simple one. The story about the Tower of Hanoi mentioned above has 64 floors), respectively. Stacking from the largest to the largest, the purpose of the game is to move the three-layer discs to the C-pillar, and still stack them in order from small to large, even if it is completed. Doesn't it look simple? That's because there are only three floors. If there are a few more floors, the difficulty will increase a lot. What if it is 64 floors?

Okay, let’s analyze first. The discs are numbered from small to large, No. 1, No. 2, No. 3. After understanding the rules of the game, we know that if we want to move the largest No. 3 to the bottom of the C-pillar, we need to put 1 No. 2 and No. 2 are moved out first, and this process will be realized by borrowing the B-pillar. We set this as the first step for the time being. There are n layers of plates, then the first step is to move n-1 plates to B, and then Some friends immediately thought of the second step. The second step is to move the Nth plate to the C-pillar. By the way, this is the second step. The next step is the key. To move the B-pillar to C, can it be regarded as the first step above, but just now it is from A to B, this time it is from B to A, and then the remaining The biggest one moved to C, doesn't it feel familiar again? By the way, it is the second step above.

After the above analysis, it is not difficult to see that, in fact, the whole process is three steps, looping back and forth, the first step moves to B except for the largest one, the second step moves the largest one to C, and the third step moves the B column to C , but the third step needs to be decomposed into the first and second steps, and so on. The next step is how to implement it with code. You don’t have to worry about the meaning of the code. You can basically understand it after reading the introductory book for 3 days. Through this, I want everyone to cultivate interest. I won’t explain the syntax of python here. Go directly to the code, and I will briefly comment on each line of code.

insert image description here

The above is the code part. Seeing that there are many words, the main reason is that there are too many comments. The real code part is actually to remove the red font at the back of each line and the long string of green fonts at the bottom. In fact, it is only 9 short lines. The code The most important three steps, just three lines of code. Next, look at the results of the operation.

insert image description here

The above is the result of the operation, that is to say, for the 3-story Tower of Hanoi, only these 7 steps are needed to complete, so no matter how many layers there are, do you only need to enter the number of layers, and then run, will each step come out immediately? ? It can be regarded as a plug-in of the Tower of Hanoi.

About Python Technical Reserve

It is good to learn Python whether it is employment or sideline business to make money, but to learn Python, you still need a study plan. Finally, everyone will share a full set of Python learning materials to help those who want to learn Python!

1. Learning routes in all directions of Python

The route of all directions in Python is to organize the commonly used technical points of Python to form a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources according to the above knowledge points to ensure that you learn more comprehensively.

2. Learning software

If a worker wants to do a good job, he must first sharpen his tools. The commonly used development software for learning Python is here, which saves you a lot of time.

3. Introductory learning video

When we watch videos and learn, we can’t just move our eyes and brain without using our hands. A more scientific learning method is to use them after understanding. At this time, the hands-on project is very suitable.

4. Practical cases

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some practical cases.

5. Interview materials

We learn Python in order to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and Ali bosses have given authoritative answers. After finishing this set The interview materials believe that everyone can find a satisfactory job.


This full version of the full set of Python learning materials has been uploaded to CSDN. If you need it, you can scan the QR code of CSDN official certification below on WeChat to get it for free【保证100%免费

Guess you like

Origin blog.csdn.net/JAVAmonster12/article/details/130035200