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.


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.9

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)(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 Allow snake to pass through walls and appear on the other side.
posion_mode bool False Add an unexpected poison food.snake will die after eating this.

🚀 Command Line Interface – python -m python_snake_game

Run the snake game directly from the command line using the module:

python -m python_snake_game [options]

📥 Available CLI Arguments

Argument Type Default Description
--speed int (1–20) 10 Controls game speed. Higher = faster. If out of range, defaults to 10.
--grid_size string (W,H) 15,12 Grid size as width,height. Must be two positive integers.
--invisible_wall flag (no value) False If set, snake wraps around screen edges instead of dying at the wall.
--posion_mode bool False Add an unexpected poison food.snake will die after eating this.

🧪 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

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

Controls

  • Arrow keys to move the snake:

    • Up arrow: Move up(w)
    • Down arrow: Move down(s)
    • Left arrow: Move left(a)
    • Right arrow: Move right(d)
  • Space bar to pause or resume the game.


How to Play

  • The snake moves continuously on the grid.
  • Eat the food (represented by the food emoji) to grow longer and increase your score.
  • Avoid hitting the walls or the snake's own body.
  • The game ends if you collide with yourself or the grid edges.
  • Use invisible_wall=True to pass through grid edges.
  • Your current score is displayed above the grid.

Notes

  • The game uses ANSI escape codes for terminal control (clear screen, 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.9.tar.gz (9.4 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.9-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_snake_game-1.0.9.tar.gz
  • Upload date:
  • Size: 9.4 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.9.tar.gz
Algorithm Hash digest
SHA256 a205c786649063f8563e61b92927cd9bb459c8dc724d0899498a56090429f632
MD5 66b1aa78877cb6aa35fe30ed9ef3d116
BLAKE2b-256 873e75c38f0f0ea685452aa8274e19e71acb7a4d817d6b104d20f6c1c75fc05c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_snake_game-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2e346bf5d1b7a3b38565e9f6a9b78991a3ac131a263e07c140311e21ec8c9fa2
MD5 8220edfb2b2a57a55e2a2de776d57c51
BLAKE2b-256 9f1e994b5b684a4e790bf27b8fce5a68e60ce4b760b7261bc7eac2a6825a04fe

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