A snake game written in Python using the Pygame library.
- Classic Snake gameplay
- Two modes: MAP (premium with obstacles) and MVP (free without obstacles)
- Themes: Light and Dark
- Sound effects and background music
- Settings persistence
- Promo codes for extending MAP mode
- Time tracking during gameplay
- Visual mode indicator on screen
- Includes obstacles (walls) for increased difficulty
- Activated via promo codes (e.g., "MAP30" for 30 minutes, "qwerty5" for 5 minutes, "qwerty10" for 10 minutes, etc.)
- Sound and music enabled
- Theme can be changed
- No obstacles, simpler gameplay
- Activated by default, no time limit
- Sound and music disabled
- Theme always black (forced)
Download the Python 3 installer package from the official website and install it, if not installed previously.
Run the following in the terminal to install the required dependencies
pip install -r requirements.txt
Download the source code from the repository and run the file just as any other Python script (.py) file.
python3 Snake\ Game.py
To start the game in MAP mode with a promo code:
python3 Snake\ Game.py --mode MAP --promo MAP30
To start the game in MVP mode:
python3 Snake\ Game.py --mode MVP
The project includes a visual testing script (visual_test.py
)
for detecting visual regressions in the game UI.
To run visual tests:
- Start the game:
python "Snake Game.py"
- In another terminal, run:
python visual_test.py
This will capture a screenshot and compare it with a baseline image. If no baseline exists, it will create one.
- Run
bandit "Snake Game.py"
for static security analysis. - Run
safety check --file requirements.txt
for dependency vulnerability checks.
This repository ships with three GitHub Actions workflows:
Quality Checks
— headless среда с запускомruff
,mypy
и unit-тестов на каждый push/pull request.Build Android APK
— сборка Android-пакета через Buildozer и загрузка артефакта.CodeFactor
— статический анализ CodeFactor. Для работы требуется секретCODEFACTOR_TOKEN
, который можно получить в личном кабинете CodeFactor (Account → Integrations → GitHub Action token) и добавить в настройках репозитория GitHub (Settings → Secrets and variables → Actions
).
Запустите их вручную на вкладке Actions или повторите локально:
ruff check .
mypy snake_game
pytest
To achieve the task of implementing two modes (MVP and MAP), the following changes were made:
- Mode Variables: Added
mode
variable ('map' or 'mvp') andmap_end_time
for timer management. - First Launch Tracking: Introduced
first_launch_time
to set a global 15-minute limit for MAP mode from the first app launch. - Settings Persistence: Updated
save_settings()
andload_settings()
to store mode, timers, and first launch time. - Theme Control: Modified
update_colors()
to force black theme in MVP mode regardless of user setting. - Sound Control: Disabled sound in MVP mode by setting
sound_enabled = False
when mode is 'mvp'. - Level Loading: Updated
load_level()
to load walls only in MAP mode. - Promo Codes: Added promo code system with 'MAP30' and various 'qwerty' codes (qwerty5, qwerty10, qwerty15, qwerty20) to extend MAP time.
- UI Notifications: Added notification when switching from MAP to MVP.
- Timer Security: Made MAP timer global to prevent abuse by closing/reopening the app.
- Time Display: Added elapsed time counter in the top-right corner during gameplay.
- Mode Indicator: Added visual indicator showing current mode (e.g., "Премиум15" for activated promo code duration, or "Классика") in the top-left corner during gameplay and pause, and in the start menu.
- Game Over Behavior: Modified game_over() to not quit the application, allowing players to restart or return to menu without relaunching.
These changes ensure fair monetization with a free MVP mode and a time-limited premium MAP mode.
The rest of the code is properly commented and self explanatory. Tweaks can be made to change the play style or visuals of the game.
- Rajat Dipta Biswas - Initial work
See also the list of contributors who participated in this project.
This project uses Dependabot for automated dependency updates. Dependabot automatically creates pull requests to update dependencies to their latest versions, helping to keep the project secure and up-to-date.
This project has been adapted to work with Kivy for Android development. Follow the steps below to build and run the application on Android devices:
- Install Kivy in your Python environment.
- Install Buildozer for building APKs.
- Ensure you have Java, Android SDK, and other dependencies required by Buildozer.
-
Initialize Buildozer in the project directory:
buildozer init
-
Edit the
buildozer.spec
file to configure your app (e.g., app name, package name, permissions). -
Build the APK:
buildozer -v android debug
-
Once the build is complete, the APK file will be located in the
bin/
directory.
Transfer the APK file to your Android device and install it manually. Ensure that "Install unknown apps" is enabled in your device settings.
After installation, launch the app from your device's app drawer. The game will run with the same features as the desktop version, including MAP and MVP modes.