DEV Community

Vũ Hoàng Lê Nguyễn
Vũ Hoàng Lê Nguyễn

Posted on

🐍 Build a Classic Snake Game with Python and Pygame on WSL using Amazon Q CLI

Image description

🎮 Snake Game

This classic Snake Game brings back nostalgic gameplay in a modern Python environment using Pygame. Built and tested on Ubuntu via WSL, this project also leverages Amazon Q CLI to streamline development, debug faster, and manage Python packages directly in the terminal — making the entire process smoother and more efficient.

Players control a growing snake that must eat red food to gain points and grow longer, while avoiding collisions with walls and its own body. As the game progresses, the challenge increases, offering an engaging experience through simple yet addictive mechanics.


🚀 Why Amazon Q CLI?

By using Amazon Q CLI, you can:

  • Get instant coding assistance for Python logic
  • Debug runtime errors in real time
  • Automate virtual environment setup and dependency management
  • Ask technical questions while coding — all directly in the CLI

Amazon Q CLI made it easier for me to stay focused and productive during the entire dev process.


🎮 How to Play

  • Run the game:
  python3 snake_game.py
Enter fullscreen mode Exit fullscreen mode
  • Controls:
    • ↑ Up arrow: Move up
    • ↓ Down arrow: Move down
    • ← Left arrow: Move left
    • → Right arrow: Move right
  • Objective:
    • Eat red food to grow and increase your score
    • Avoid hitting the walls or your own body
  • After Game Over:
    • Press Q to quit
    • Press C to play again

🔥 Game Features

  • Real-time score tracking
  • Increasing difficulty as the snake grows
  • Game Over screen with restart option
  • Smooth controls and collision detection

💻 Requirements

  • Python 3
  • Pygame library
  • WSL (Ubuntu 22.04 recommended)
  • Amazon Q CLI (optional but highly recommended)

📦 Installation Steps

  1. Ensure Python 3 is installed:
   python3 --version
Enter fullscreen mode Exit fullscreen mode
  1. Install Pygame:
   pip install pygame
Enter fullscreen mode Exit fullscreen mode
  1. Clone or download this project.

  2. Run the game:

   python3 snake_game.py
Enter fullscreen mode Exit fullscreen mode
  1. (Optional) Use Amazon Q CLI:
   q help
Enter fullscreen mode Exit fullscreen mode

🧠 Code Structure

  • snake_game.py
    • Game window setup
    • Snake movement and logic
    • Food generation
    • Collision detection
    • Score tracking
    • Game restart/quit logic

🌱 Future Improvements

  • Add sound effects
  • Introduce multiple difficulty levels
  • Save and display high scores
  • Add obstacles or maze elements
  • Add power-ups for special abilities

📸 Screenshot

(Bạn có thể chèn ảnh minh họa game tại đây)

![Snake Game Screenshot](https://link-den-anh-game.png)
Enter fullscreen mode Exit fullscreen mode

🪪 License

This project is open-source and free to use, modify, and improve!

Top comments (0)