Today, share an interesting Python Game library freegames, It contains 20 Remaining classic games , Like a greedy snake , Bean eater , Table tennis , Digital Huarong Road, etc , Rely on the standard library Turtle.

We can not only pass 1 Line code to review these childhood games , You can also view the source code and learn to write the game yourself , Awesome !

catalogue :

1. install
2. Basic introduction
3. Game demo
4. Source code view

1. install

adopt pip Simple installation , The latest version is 2.3.2

pip install freegames

 

2. Basic introduction

After installation , We can view relevant information through the following instructions

# View the list of existing games
!python -m freegames list # stay jupyter notebook
python -m freegames list # In the command line interface

 

View the list of existing games # view help
help(freegames)
# It can also be used ? stay jupyter notebook
import freegames
freegames?

view help

 

3. Game demo

Here we introduce several familiar games , And demonstrate

Paint Graffiti draws lines and shapes on the screen

Click to mark the beginning of the shape , Then click again to mark its end ;
You can use the keyboard to choose different shapes and colors .
!python -m freegames.paint # If on the command line , Then remove the front exclamatory mark !

Graffiti
Snake Gluttonous snake Classic arcade games

 

Use the direction keys on the keyboard to navigate and eat green food , Every time you eat food , The snake will grow for a while ;
Avoid eating yourself or crossing the line .
!python -m freegames.snake

 

Gluttonous snake
Pacman Bean eater Classic arcade games

Use the arrow keys to navigate and eat all the white food ;
Beware of the red ghosts roaming the maze , Kneel when you touch it .
!python -m freegames.pacman

Bean eater
Cannon artillery

 

Click on the screen to launch your cannon , The shell blew up the blue balloon in its path ;
Blow up all the balloons before they cross the screen .
!python -m freegames.cannon

artillery
Flappy Flappy-bird Class game

 

Click on the screen to flap your wings ;
When you fly over the screen , Please be careful not to touch black crows .

Flappy Bird
Pong Table tennis Classic arcade games

 

Use the keyboard to move the racket up and down , The first player who missed the ball lost

!python -m freegames.pong

 

Table Tennis
Tiles Digital huarongdao Puzzle game that slides numbers to a specified position

Click the block adjacent to the empty square to swap positions , You can make the numbers from left to right and from bottom to top 1 reach 15 Is it ?

!python -m freegames.tiles

 

Digital huarongdao
There are more games , You can experience it by yourself , If you are interested, you can also study the source code and learn how to write it python Games !

4. Source code view

adopt copy Relevant source files can be copied locally , Then check the source code , We can learn according to the source code !

!python -m freegames copy snake

 

snake Source file Preview
The above is all about this time , Interested friends can install this library to play with , Learn to write a little game by yourself !

-------------------End ---------------

Don't spray if you don't like it , thank you
 

 

Technology