DEV Community

Cover image for ๐ŸŽฏ Solving Puzzles with Code: A Math Adventure Game Built with Amazon Q CLI

๐ŸŽฏ Solving Puzzles with Code: A Math Adventure Game Built with Amazon Q CLI

Math Adventure: An Interactive Educational Math Game for Grades 1-5

Math Adventure is a dynamic, grade-progressive educational game that helps students practice math operations through an engaging interactive interface. The game adapts to student performance, automatically advancing through grade levels as players demonstrate mastery of mathematical concepts.

The game features a carefully designed difficulty progression system that introduces new mathematical operations and larger numbers as students advance through grades 1-5. Starting with simple addition and subtraction with numbers up to 10, it gradually incorporates multiplication and division with larger numbers up to 200. The game provides immediate feedback, tracks lives and scores, and includes visual rewards for correct answers and level progression.

Game Demo

Github Repository

GitHub logo mohamednizzad / mathsadventure

This is a simple project for Amazon Q CLI Game Challenge Developed along with my kid

Math Adventure - Educational Game

A fun and educational math game designed for students in grades 1-5, built with Pygame.

Features

  • Progressive difficulty levels matching grades 1-5
  • Interactive and engaging gameplay
  • Various math operations (addition, subtraction, multiplication, division)
  • Colorful graphics and sound effects
  • Score tracking and achievements

Requirements

  • Python 3.7+
  • Pygame

Installation

  1. Clone this repository
  2. Install requirements:
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Running the Game

python src/main.py
Enter fullscreen mode Exit fullscreen mode

Testing

python -m pytest tests/
Enter fullscreen mode Exit fullscreen mode

Project Structure

.
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ game.py
โ”‚   โ”œโ”€โ”€ levels.py
โ”‚   โ””โ”€โ”€ utils.py
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_game.py
โ”‚   โ””โ”€โ”€ test_levels.py
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ fonts/
โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ””โ”€โ”€ sounds/
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md



Repository Structure

math-adventure/
โ”œโ”€โ”€ requirements.txt     # Python package dependencies (pygame, pytest)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ game.py         # Core game logic, UI, and game state management
โ”‚   โ”œโ”€โ”€ levels.py       # Math problem generation and difficulty scaling
โ”‚   โ””โ”€โ”€ main.py         # Application entry point and pygame initialization
โ””โ”€โ”€ tests/              # Test suite directory
    โ”œโ”€โ”€ test_game.py    # Game mechanics and UI tests
    โ””โ”€โ”€ test_levels.py  # Math problem generation tests
Enter fullscreen mode Exit fullscreen mode

Usage Instructions

Prerequisites

  • Python 3.6 or higher
  • pip (Python package installer)

Installation

Clone the repository:

git clone https://github.com/mohamednizzad/mathsadventure.git
cd math-adventure
Enter fullscreen mode Exit fullscreen mode

Create and activate a virtual environment:

# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux
python3 -m venv venv
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Install dependencies:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Quick Start

Run the game:

python src/main.py
Enter fullscreen mode Exit fullscreen mode

Game Controls:

  • Enter numbers using the keyboard
  • Press Enter to submit your answer
  • Press Backspace to delete input
  • Press 'R' to restart when game is over
  • Press 'Q' to quit when game is over

More Detailed Examples

Grade 1 Problems:

  • Addition and subtraction with numbers 1-10
  • Example: "5 + 3 = ?"

Grade 2 Problems:

  • Addition and subtraction with numbers 1-20
  • Example: "15 - 7 = ?"

Grade 3 Problems:

  • Addition, subtraction, and multiplication
  • Numbers up to 50
  • Example: "6 * 8 = ?"

Grade 4 Problems:

  • All operations including division
  • Numbers up to 100
  • Example: "48 รท 6 = ?"

Grade 5 Problems:

  • Advanced operations with larger numbers
  • Numbers up to 200
  • Example: "156 + 44 = ?"

Troubleshooting

Pygame Installation Issues:

# Windows
pip install --upgrade pip
pip install pygame --pre

# Linux
sudo apt-get install python3-pygame
Enter fullscreen mode Exit fullscreen mode

Display Issues:

  • Ensure your display resolution is at least 800x600
  • Try updating your graphics drivers

Performance Issues:

  • Check CPU usage with Task Manager/Activity Monitor
  • Close other resource-intensive applications
  • Verify pygame version is 2.1.0 or higher

Data Flow

The game processes math problems through a generate-solve-validate cycle, with progressive difficulty scaling based on player performance.

[User Input] -> [Problem Generator] -> [Game Logic] -> [UI Renderer]
     ^                                      |
     |                                     v
[Score/Lives Update] <- [Answer Validation] <- [Player Response]
Enter fullscreen mode Exit fullscreen mode

Component Interactions:

  1. Problem Generator creates grade-appropriate math problems
  2. Game Logic manages game state and processes user input
  3. UI Renderer displays problems and feedback
  4. Answer Validation checks responses and updates game state
  5. Score/Lives system tracks player progress
  6. Grade progression system monitors score thresholds
  7. Feedback system provides immediate response to player actions

Bonus

Checkout my article that won the Amazon Q Developer Challenge

Heroku

Amplify your impact where it matters most โ€” building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post