Skip to main content

A classic Snake game implementation in Python using curses

Project description

Snake Game

A classic Snake game implemented in Python using the curses library. This terminal-based game features colorful graphics, score tracking, and an intuitive interface.

Demo

Snake Game Demo

Features

  • Colorful terminal-based UI
  • Score and high score tracking
  • Direction-aware snake appearance
  • Game over screen with restart option
  • Persistent high score storage

Requirements

  • Python 3.6 or higher
  • curses library (included in standard Python distribution)

Installation & Running

There are two ways to install and run the game:

Method 1: Using pip (Recommended)

  1. Install the package:

    pip install terminal-snake-game
    
  2. Run the game:

    # Either use the command-line tool
    snake-game
    
    # Or run as a Python module
    python3 -m snake_game
    

Method 2: From Source

  1. Clone the repository:

    git clone git@github.com:SwetaTanwar/snake-game.git
    cd snake-game
    
  2. Run the game:

    # Using Python directly
    python3 snake_game.py
    

    Or make it executable first:

    # Make the script executable
    chmod +x snake_game.py
    
    # Then run directly
    ./snake_game.py
    

How to Play

Controls

  • Use arrow keys (↑ ↓ ← →) to control the snake
  • Eat ★ to grow and score points
  • Press 'q' to quit
  • Press 'r' to restart after game over

Game Elements

  • 🐍 Snake head shows direction (▶ ◀ ▲ ▼)
  • ◆ Snake body
  • ★ Food
  • Score and high score display at the top
  • Control instructions at the bottom

Development and Testing

Setting up Development Environment

  1. Create a virtual environment:

    python -m venv test_env
    source test_env/bin/activate  # On Unix/macOS
    # or
    test_env\Scripts\activate  # On Windows
    
  2. Install development dependencies:

    pip install -e ".[test]"
    

Running Tests

The game includes a comprehensive test suite that verifies core functionality. To run the tests:

# Run all tests
python -m pytest src/tests/

# Run tests with verbose output
python -m pytest src/tests/ -v

# Run tests with coverage report
python -m pytest src/tests/ --cov=terminal_snake_game

The test suite covers:

  • Snake movement and collision detection
  • Food generation and placement
  • Score tracking
  • Window management and display
  • Game mechanics validation

When contributing new features, please ensure to:

  1. Add appropriate test cases
  2. Run the full test suite before submitting changes
  3. Maintain or improve the current test coverage

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

terminal_snake_game-1.0.4.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

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

terminal_snake_game-1.0.4-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file terminal_snake_game-1.0.4.tar.gz.

File metadata

  • Download URL: terminal_snake_game-1.0.4.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for terminal_snake_game-1.0.4.tar.gz
Algorithm Hash digest
SHA256 4dacf793e1613bc5a59c681cab316144c681340d3e86f2678f7bb4648abf7b18
MD5 9b8716581e6ba2614562e8083a148eab
BLAKE2b-256 f3c4826c27e236af5d6c895f2f0fa53c1673e38922a48d0a30463926483b1f9a

See more details on using hashes here.

File details

Details for the file terminal_snake_game-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for terminal_snake_game-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f408e6f16cda1b8705787574fbe1dd16dc5f54f75335a98822ae1e94218c47aa
MD5 c6ad528e6d59be358da34d346f3c2296
BLAKE2b-256 64ac06bb1e04899587cae50f135f0324eda4f4d3001e67cbd46849f16a94e426

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