A simple 2D game built with Python and the Pygame Zero library. The objective is to control a fox and collect as many coins as possible before the timer runs out.
This project is based on an example from the book "Coding Games in Python" by DK, with refactoring to improve structure, maintainability, and testability.
- Scoring: Gain 10 points for every coin collected.
- Countdown Timer: The game lasts for 10 seconds.
- Game Over: A final score screen is displayed when time runs out.
- Unit Tests: The project includes a test suite using
pytestto verify game logic.
You can control the fox using either the WASD keys or the Arrow Keys.
- Move Up:
WorUp Arrow - Move Down:
SorDown Arrow - Move Left:
AorLeft Arrow - Move Right:
DorRight Arrow
- Python 3.x
- Pygame Zero
- Pytest (for running the tests)
-
Clone or download the repository: If you have Git, you can clone it. Otherwise, download the project files as a ZIP.
-
Navigate to the project directory:
cd path/to/CoinCollector -
Install the required libraries:
pip install pgzero pytest
For a simpler way to play without installing Python, you can download a pre-built executable from the project's Releases page on GitHub.
- Go to the repository's Releases tab.
- Download
coincollector.exe(only tested on Windows). - Run the downloaded file to play. Note Windows Defender might yell at you when you run the .exe because I haven't bought a signing certificate from Microsoft. This is malware-free. That's just my word you're going on.
To run the game, execute the coincollector.py script using the pgzrun command in your terminal from the project's root directory:
pgzrun coincollector.pyTo ensure the game logic is working correctly, you can run the automated tests. From the project's root directory, simply run pytest:
pytestThe project is structured to separate game code from tests.
CoinCollector/
├── coincollector.py # Main game logic and Pygame Zero hooks
├── images/ # Contains all image assets for the game
│ ├── coin.png
│ └── fox.png
├── tests/ # Contains all tests for the project
│ ├── __init__.py # Makes the 'tests' directory a Python package
│ └── test_coincollector.py # Unit tests for the game logic
├── .gitignore # Specifies files for Git to ignore
└── README.md # This file
