Programming mini game to make plant zombies, python programming mini game is simple

This article mainly introduces the programming mini-game to make plant zombies, which has certain reference value. Friends in need can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to understand it together.

Today I will share an interesting Pythongame library freegames, which contains more than 20 classic mini-games, such as Snake, Pac-Man, Ping Pong, Digital Huarong Road, etc., relying on the standard library Turtle.

Not only can we relive these childhood games through one line of code, but we can also view the source code and learn how to write games ourselves, which is awesome!

# 1. Installation

Through pipsimple installation, the latest version is2.3.2

pip install freegames

# 2. Basic introduction

After the installation is complete, we can view relevant information through the following command

# 查看已有游戏列表
!python -m freegames list # 在jupyter notebook
python -m freegames list # 在命令行界面

View the list of existing games

# 查看帮助
help(freegames)
# 也可以用 ? 在jupyter notebook
import freegames
freegames?

View help

# 3. Game Demo

Here we introduce several well-known mini-games and demonstrate them

Paint  draws lines and shapes on the screen

  1. Click to mark the beginning of the shape, then click again to mark its end;

  2. There are several ways to install the python installation package using the keyboard to select different shapes and colors .

!python -m freegames.paint # 如果在命令行,则去掉前面的 感叹号 !

Graffiti

Snake is  a classic arcade game

  1. Use the keyboard's arrow keys to navigate and eat green food. Each time you eat food, the snake will grow a length;

  2. Avoid eating yourself or crossing the line.

!python -m freegames.snake

Snake

Pacman Pacman  classic arcade game

  1. Use the arrow keys to navigate and eat all the white food;

  2. Watch out for the red ghosts that roam the maze, they will kneel down when you encounter them.

!python -m freegames.pacman

pacman

Cannon

  1. Tap the screen to fire your cannon and the cannonball will blow up blue balloons in its path;

  2. Blow up all the balloons before they cross the screen.

!python -m freegames.cannon

cannon

Flappy Flappy-bird games

  1. Tap the screen to flap your wings;

  2. As you fly across the screen, be careful not to hit the black crow.

Flappy Bird

Pong table tennis  classic arcade game

Use the keyboard to move the racket up and down, the first player to miss the ball loses

!python -m freegames.pong

pingpong

Tiles Digital Huarongdao  is a puzzle game that slides numbers to designated positions.

Click on the tiles adjacent to the empty squares to swap places. Can you make the numbers 1 to 15 from left to right and bottom to top?

!python -m freegames.tiles

Digital Huarong Road

There are more games that you can experience on your own. If you are interested, you can also study the source code and learn how to write python games!

# 4. View source code

By copycopying the relevant source files locally and then viewing the source code, we can learn based on the source code!

!python -m freegames copy snake

snake source file preview

The above is the entire content of this article. Interested friends can install this library to play with it, and learn to write a small game by themselves!

The above is all the content shared this time. If you think the article is good, welcome to follow the public account: Python Programming Learning Circle , share daily useful information, and send "J" to receive a large amount of learning materials. Or go to the Programming Learning Network to learn more about programming technology.

Guess you like

Origin blog.csdn.net/chatgpt002/article/details/133034246