Skip to main content

A simple Snake game written in Python for the command-line interface (CLI). Control the snake with arrow keys, eat food to grow, and avoid running into yourself. Built entirely with Python's standard libraries-no third-party packages required.

Project description


Simple Snake Game 🐍

A minimalist snake game written in Python using asyncio. Customize speed, grid size, controls, and even add a poison mode for extra challenge!


Author


Installation

Install the game easily using pip:

From PyPI:

pip install python-snake-game

Or directly from GitHub:

pip install git+https://github.com/ramimK0bir/python-snake-game@v1.0.10

Usage

You can import and run the game from Python code:

import python_snake_game as snake_game

snake_game.play()

Parameters of play function

Parameter Type Default Description
speed int 10 Controls the game speed (higher = faster; range 1–20).
snake_food_emoji str "🍎" Emoji to represent the food on the grid.
grid_size tuple (int,int) (15,12) Size of the game grid as (width, height).
background_emoji str "🟫" Emoji or character to represent the grid blocks.
invisible_wall bool False Snake wraps around edges instead of dying.
poison_mode bool False Adds poisonous food. Snake dies if eaten.

Key Customization Functions

The game allows full key customization via three built-in functions:

  1. automatic_configure_custom_key() Interactively prompts the user at runtime to configure custom keys for movement and pause.

  2. manual_configure_custom_key() Allows the user to edit a configuration file to set preferred keys and save them for future sessions.

  3. reset_key_configuration() Restores default key bindings, undoing any previous customizations.

Example Usage

import python_snake_game as snake_game

# Automatic interactive key configuration
snake_game.automatic_configure_custom_key()

# Manual configuration via config file
snake_game.manual_configure_custom_key()

# Reset keys to default
snake_game.reset_key_configuration()

# Start the game after customizing keys
snake_game.play(speed=10, grid_size=(20, 15), poison_mode=False)

🚀 Command Line Interface – python -m python_snake_game

Run the snake game directly from the command line:

python -m python_snake_game [options]

📥 Available CLI Arguments

Argument Type Default Description
--speed int (1–20) 10 Controls game speed. Higher = faster.
--grid_size string (W,H) 15,12 Grid size as width,height. Must be two positive integers.
--invisible_wall bool False Snake wraps around screen edges instead of dying.
--poison_mode bool False Adds poisonous food. Snake dies if eaten.
--customize_key bool False Enable interactive or file-based key customization before playing.

🧪 Examples

# Run with default settings
python -m python_snake_game

# Custom speed and grid size
python -m python_snake_game --speed 5 --grid_size 20,15

# Enable invisible walls (screen wrapping)
python -m python_snake_game --invisible_wall

# Enable poison mode
python -m python_snake_game --poison_mode

# Customize keys interactively before start game
python -m python_snake_game --customize_key

# All options together
python -m python_snake_game --speed 8 --grid_size 30,20 --invisible_wall --poison_mode --customize_key

Controls

  • Arrow keys (default) to move the snake:

    • Up: w
    • Down: s
    • Left: a
    • Right: d
  • Space bar to pause/resume the game.

  • Custom keys can be configured via CLI or the three customization functions.


How to Play

  • The snake moves continuously on the grid.
  • Eat the food (🍎) to grow longer and increase your score.
  • Avoid hitting walls or your own body unless invisible_wall=True.
  • In poison mode, some food can kill the snake instantly.
  • Current score is displayed above the grid.

🆕 What's New in v1.0.10

  • Custom Key Configuration

    • Automatic – interactively configure keys via automatic_configure_custom_key().
    • Manual – configure keys by editing a configuration file via manual_configure_custom_key().
    • Reset – restore default key bindings using reset_key_configuration().
  • New CLI Argument: --customize_key to trigger key customization before playing.


Notes

  • Uses ANSI escape codes for terminal control (screen clear, colors).
  • Works best on terminals supporting Unicode and ANSI colors.

License

This project is open source. Feel free to contribute or modify!


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_snake_game-1.0.10.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_snake_game-1.0.10-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file python_snake_game-1.0.10.tar.gz.

File metadata

  • Download URL: python_snake_game-1.0.10.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for python_snake_game-1.0.10.tar.gz
Algorithm Hash digest
SHA256 465487d1fd2cdb07d379fc10e475c588b01db15df5124e129efa61068ccd29a7
MD5 12e48bd9b2b2d6895d1243b64c3bbcd7
BLAKE2b-256 738b601000da44eb280e257cf70fccde57add989db23295091a2793c34057d7e

See more details on using hashes here.

File details

Details for the file python_snake_game-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for python_snake_game-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ce6ee8e0e48f16a95e3dbcad6e20df9842f7283b75462bfa5c6dfaa8077e34d1
MD5 7cc629d606090c0618aed0b9159cfcab
BLAKE2b-256 ba928a172b1b56e83bc925758c2cb69ab9bce41ca8b91e2ab9c8c1f2da75c780

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page