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 make python version 4399 eat Doudou Mini Game

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to make python version 4399 eat Doudou Mini Game, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

Text

Python version: 3.6.4

Related modules:

Pygame module

And some modules that come with Python.

Module self-installation, environment installation package and other novice rookies will not be able to talk directly in private about the editor's first installation environment!

Let's first take a look at the effect of a wave of implementation code:

Game introduction:

Players through the ↑↓←→ key to control the protagonist of the game Pac-Man to eat all the beans hidden in the maze, and can not be caught by ghosts.

If you can successfully eat all the beans in the maze and not be caught by ghosts, the game will win, otherwise the game will fail.

Step by step:

Step1: define game genie classes

First of all, let's make it clear which game elves are needed for the game.

① wall class

② food category (I. e. Beans)

③ role class

Characters include Pac-Man and ghosts. Ghosts control their trajectories by computers, while Pac-Man players control their trajectories.

Obviously, all of them need the ability to update the position of the character and change the direction of the character's movement, and the source code is as follows:

Step2: designing game maps

Using the game genie classes defined in Step1, we can start designing game maps. Due to the limited time, I only wrote a game map of the level, and interested partners can expand on this basis (it is very convenient to expand on the basis of my source code). The design of the game map includes the following four aspects:

① creates a wall

② create door (used to close ghosts at first)

③ creates roles

④ creates food

Because food cannot overlap with the positions of walls, doors, and characters, in order to facilitate the design of game maps, create walls, doors, and characters before creating food:

Step3: design the game main cycle

Next, start designing the main cycle of the game. The first is initialization:

Then define the main function:

The startLevelGame function is used to start a certain game. Its source code is as follows:

The showText function is used to display prompting text in the game interface at the end of the game or when the level is switched. The source code is as follows:

Ok, game-related article picture material, complete project code editor has been sorted out.

The above content is how to make python version 4399 eat Doudou Mini Game, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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