Connect Four is a two-player connection game in which the players first choose a color and then take turns dropping one colored disc from the top into a seven-column, six-row vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own discs.
To use this project.
- Install dependencies & export environment variables.
$ sudo -H pip3 install -r requirements.txt- Start project using
$ python3 game.py- Add a file structure here with the basic details about files, below is current file structure.
.
├── assets.py
├── config.py
├── connect_game.py
├── events.py
├── game_board.py
├── game_data.py
├── game_renderer.py
├── game.py
├── images
│ ├── blackball91px.png
│ ├── logo
│ │ └── connect4.png
│ ├── redball90px.png
│ ├── screenshots
│ │ ├── 1.png
│ │ └── 2.gif
│ └── yellowball90px.png
├── LICENSE
├── README.md
├── requirements.txt
├── restart.sh
└── sounds
├── disc_drop_1.wav
├── disc_drop_2.wav
└── event.ogg
4 directories, 21 files
| No | File Name | Details |
|---|---|---|
| 1 | assets.py | used for loading sound and image files in python. |
| 2 | config.py | contains game's configuration settings. |
| 3 | connect_game.py | Contains the ConnectGame class which holds the logic for the whole game. |
| 4 | events.py | Contains classes used to define and hold event data. |
| 5 | game_board.py | Contains the GameBoard data structure and methods which operate on it. |
| 6 | game_data.py | Contains the GameData class, which contains all of the data in the game. |
| 7 | game_renderer.py | Holds the GameRenderer class, which renders the game state using sound and graphics. |
| 8 | game.py | contains connect four game logic. |
| 9 | images/ | contains image resources used in the game. |
| 10 | images/logo | contains logo used in the README. |
| 11 | images/screenshots | contains game screenshots. |
| 12 | LICENSE | this project uses MIT License. |
| 13 | requirements.txt | contains all the dependencies used in the game. |
| 14 | restart.sh | bash script to relaunch the game once it is finished. |
| 15 | sounds/ | contains sound resources used in the game. |
- Dependency Graph
- Code Style
In order to maintain the code style consistency across entire project I use a code formatter. I kindly suggest you to do the same whenever you push commits to this project.
The python code formatter I chose is called Black. It is a great tool and it can be installed quickly by running
sudo -H pip3 install blackor
python3.6 -m pip install blackIt requires Python 3.6.0+ to run.
- Usage
black {source_file_or_directory}For more details and available options, please check their psf/black.
I also use isort, it is a Python utility / library to sort imports alphabetically, and automatically separated into sections. It provides a command line utility which can be installed using.
sudo -H pip3 install isort - Usage
isort {source_file}.pyFor more details and available options, please check their timothycrosley/isort.
- Close Issues
Close issues using keywords: how to ?
- PyGame Documentation : Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language.


