DEV Community

Cover image for Prompting a Classic Snake Game using Amazon Q
Earl John Pulido
Earl John Pulido

Posted on

Prompting a Classic Snake Game using Amazon Q

Remember the good old days of playing Snake on your Nokia phone? That simple yet addictive game where you guide a growing serpent around the screen, gobbling up food while avoiding your own tail? Well, I decided to recreate this classic using Amazon Q CLI - Amazon's AI-powered coding assistant that can help you build applications through natural language prompts.

In this post, I'll walk you through my journey of building a fully functional Snake game using nothing but conversational prompts with Amazon Q CLI. Spoiler alert: it was surprisingly smooth and educational!

What is Amazon Q CLI?

Amazon Q CLI is an AI coding assistant that lets you build applications through natural language conversations. Instead of writing code from scratch, you can describe what you want to build, and Q helps generate, modify, and debug code through an interactive chat interface.

The Challenge: Building Snake with Prompts

My goal was simple: create a playable Snake game using only prompts to Amazon Q CLI. No pre-written code, no copying from tutorials - just pure AI-assisted development through conversation.

Game Requirements:

  • A snake that moves continuously
  • Food that appears randomly on the screen
  • Score tracking
  • Game over when snake hits walls or itself
  • Smooth gameplay with proper frame rate

My Development Journey

Starting Simple: "Build me a Snake game"
My first prompt was straightforward:

"Help me create a Snake game in Python using PyGame. I want a basic version with a snake that moves around the screen and eats food."
Enter fullscreen mode Exit fullscreen mode

Amazon Q immediately understood the request and provided a solid foundation with:

  • Basic PyGame setup
  • Snake movement mechanics
  • Food generation system
  • Collision detection

The initial code was surprisingly complete and functional!

Refining Through Conversation

What impressed me most was how I could iterate on the game through natural conversation:
Me: "The snake moves too fast, can you slow it down?"
Amazon Q: Adjusted the frame rate and movement timing
Me: **"Add a score display in the top-left corner"
**Amazon Q:
Implemented score rendering with proper font handling
Me: "Make the food appear in different colors randomly"
Amazon Q: Enhanced the food system with color variation

Advanced Features Through Prompts

As I got more comfortable, I asked for more sophisticated features:

"Add sound effects when the snake eats food and when the game ends"
"Make the snake speed up slightly as it gets longer"
"Add a game over screen with restart functionality"
"Implement proper boundary collision detection"
Each request was handled smoothly, with Amazon Q explaining the changes and ensuring the code remained clean and well-structured.
Enter fullscreen mode Exit fullscreen mode

Key Features Implemented

Here's what we built together:
Core Gameplay

  • Smooth Movement: Snake moves in grid-based steps
  • Food System: Randomly placed food items with color variation
  • Growth Mechanics: Snake grows when eating food
  • Collision Detection: Walls and self-collision end the game

User Experience

  • Score Display: Real-time score tracking
  • Progressive Difficulty: Speed increases with length
  • Game Over Screen: Clear end state with restart option
  • Visual Polish: Clean graphics with distinct colors

Technical Implementation

  • Efficient Rendering: Optimized drawing loops
  • Event Handling: Responsive keyboard controls
  • Game State Management: Proper game loop structure
  • Error Handling: Robust collision and boundary checking

Code Highlights

While I won't include the entire codebase here, here are some interesting snippets that Amazon Q helped create:

def game_over_screen(score):
    """Display game over screen with restart functionality"""
    game_over_sound.play()

    game_exit = False

    while not game_exit:
        game_display.fill(white)
{% embed  %}
        message("GAME OVER", dark_red, -50, "large")
        message(f"Final Score: {score}", black, 0)
        message("What would you like to do?", black, 50)

        # Create buttons
        restart = draw_button("Play Again", 150, 400, 200, 50, green, (0, 200, 0))
        quit_game = draw_button("Quit", 450, 400, 200, 50, red, dark_red)

        pygame.display.update()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        if restart:
            game_loop()
        if quit_game:
            pygame.quit()
            quit()

        clock.tick(15)

Enter fullscreen mode Exit fullscreen mode

Try It Yourself!
Want to build your own Snake game or try other projects with Amazon Q CLI? Check out the "Build Games with Amazon Q CLI" campaign running until June 20, 2025. You might even earn a cool T-shirt while learning!
Campaign hashtag: #AmazonQCLI

Have you tried building games with AI assistance? Share your experiences in the comments below!

Top comments (0)