Connect-Py is a classic Connect 4 game implementation built with Python, Pygame, and NumPy. It features a fully interactive graphical interface, local 2-player support, and robust game logic.
- Classic Gameplay: Standard 6x7 grid with gravity-based piece dropping.
- Local Multiplayer: Play against a friend on the same machine.
- Interactive UI: Mouse-controlled piece placement with real-time hovering.
- Win Detection: Automatically detects wins (horizontal, vertical, diagonal) and announces the winner.
- Restart Functionality: Click anywhere after a game ends to instantly reset the board.
- Python 3.13 or higher
- uv (recommended) OR standard
pip
This project is managed with uv. To run it immediately with all dependencies handled:
uv run main.pyIf you prefer standard pip, install the required dependencies first:
pip install pygame numpyThen run the game:
python main.py- Launch the game.
- Player 1 (Blue) starts first.
- Move your mouse horizontally across the top of the window to position your chip.
- Click the left mouse button to drop the chip into the selected column.
- Player 2 (Yellow) takes the next turn.
- The first player to connect 4 chips in a row (horizontally, vertically, or diagonally) wins!
- Click anywhere on the screen after a win to restart the game.
main.py: The entry point. Handles the main game loop, input processing, and game coordination.board.py: Contains theBoardclass, managing the game state (grid), move validation, and win algorithms.ui.py: Handles all Pygame rendering, including the board, pieces, and text.
Unit tests have been implemented for the core game logic, primarily focusing on the Board class.
To run the tests, navigate to the project root directory and execute:
PYTHONPATH=. .venv/bin/pytest- BigBlueTerm Nerd Font: Used for its retro aesthetic.
This project is licensed under the GPL 3 License. See the LICENSE file for details.