How I Built a Memory Game Using Amazon Q CLI and PyGame

Le VuLe Vu
4 min read

TL;DR: I asked Amazon Q CLI to build a memory card game in Python. It said “sure,” and gave me working code with a score system, restart logic, and zero stack overflow searches. PyGame + AI pair-programming = actual magic. Code, screenshots, bugs, and laughs ahead.


🎯 Why a Memory Game?

I wanted something:

  • Small enough for AI to generate without imploding

  • Visual enough to not bore me to tears

  • Stateful enough to test how “smart” Q really is

Also: matching colorful boxes is way more fun than debugging nested dictionaries.


🛠 Setting Up Amazon Q CLI on Windows (WSL to the Rescue)

Spoiler: Q CLI doesn’t run natively on Windows. So I summoned WSL (Windows Subsystem for Linux) like the seasoned Linux poser I am.

Step 1: Enable WSL and install Ubuntu

wsl.exe --install --no-distribution
# Then reboot like a good dev

Then open your terminal and summon the penguin:

wsl -d Ubuntu
sudo apt update && sudo apt install unzip curl python3 python3-pip

Step 2: Install Q CLI

curl --proto '=https' --tlsv1.2 -sSf https://desktop-release.codewhisperer.us-east-1.amazonaws.com/latest/q-x86_64-linux-musl.zip -o q.zip
unzip q.zip
cd q
chmod +x install.sh
./install.sh

Now the fun begins:

q chat

🗨️ The Prompt That Started It All

Inside the Q CLI terminal, I typed one humble request:

"I want to build a simple "Memory Matching" game using Python and the Pygame library."

A few seconds later, Q casually handed me:

memory_game.py

Cool. Cool cool cool.


🧠 What the Game Actually Does

This thing works. Like... plays like a real game works.

Here’s what it includes:

  • 🃏 12 cards (6 color pairs), randomly shuffled

  • 👆 Click to flip 2 cards → match or mismatch

  • 🎯 Score system: +10 for correct, -1 for wrong

  • 🔁 Restart button after all pairs are found

And it looks like this:

Game screenshot


🧩 The Matching Logic (In Case You’re Curious)

# Check if the cards match
if cards[first_selection][1] == cards[second_selection][1]:
    score += 10
    matches_found += 1
    # Reset selections
    first_selection = None
    second_selection = None
else:
    # Penalty for wrong match
    score = max(0, score - 1)

Simple. Elegant. Brutal to bad guesses.

Game Reset Function:

# Check if game is over
if check_game_over():
    font = pygame.font.Font(None, 48)
    game_over_text = font.render("Game Over! You Win!", True, BLACK)
    DISPLAY_SURFACE.blit(game_over_text,
                        (WINDOW_WIDTH // 2 - game_over_text.get_width() // 2,
                         WINDOW_HEIGHT // 2 - game_over_text.get_height() // 2))
    pygame.display.update()
    pygame.time.wait(3000)  # Wait 3 seconds
    initialize_game()  # Restart the game

This is the part Q somehow understood we’d need. Didn’t even have to ask twice.


🧪 Running the Game

If you’re in WSL:

sudo apt install python3-pygame
python3 memory_game.py

If you’re in a virtualenv (a.k.a. your happy Python bubble):

python3 -m venv venv
source venv/bin/activate
pip install pygame
python memory_game.py

Either way: prepare for rectangles and regrets.


💡 What I Learned from Q (Besides the Fact It’s Smarter Than Me)

🧙 Prompt clarity = cleaner code

The more specific I was, the better Q understood me. (Honestly… just like humans.)

🧠 Q remembers stuff

It builds on previous files instead of overwriting them. Like a respectful AI roommate.

💻 It feels like pair programming

…except your pair never sleeps, complains, or pushes broken code at 2AM.


🎁 Want to Try It Yourself?

Here’s your game dev starter pack:


💬 Final Thoughts

From prompt to playable in under an hour. Bugs became teaching moments. Fixes took seconds, not stack traces. And I now have a memory game I can proudly pretend I hand-coded.

You should try it. Worst case? You get a half-working game. Best case? You ship something fun while your coffee is still warm ☕🎮


Let me know if you'd like:

  • The full source code

  • A version with sound effects

  • Or... a snake game next? 🐍


👉 Follow me for more AI-assisted dev adventures. Or just stick around for the screenshots and sarcasm.

0
Subscribe to my newsletter

Read articles from Le Vu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Le Vu
Le Vu