DEV Community

Cover image for Build AWS Cloud Services Hangman Game with Amazon Q CLI
Nowsath for AWS Community Builders

Posted on

Build AWS Cloud Services Hangman Game with Amazon Q CLI

Are you looking for a fun way to learn AWS service names while enjoying a classic game? In this blog post, I'll walk you through an AWS-themed Hangman game I
built using Python and Pygame. This educational game helps players become familiar with AWS service names across different categories - perfect for AWS
certification candidates or anyone interested in cloud computing.

Game Overview

The AWS Cloud Services Hangman game challenges players to guess AWS service names one letter at a time. With 8 different AWS service categories and over 80
services to guess, it's both entertaining and educational.

AWS Hangman Game

Key Features:

• Multiple AWS service categories (Compute, Storage, Database, etc.)
• Interactive letter selection
• Visual hangman drawing that builds with each wrong guess
• Score tracking
• Custom AWS-themed background
• Clean and intuitive user interface

How the Game Works

When you start the game, you're presented with a menu screen featuring the AWS Cloud Services title. After clicking "Play Game," you select from various AWS
categories like Compute, Storage, or Database. The game then randomly selects an AWS service from that category for you to guess.

You have six attempts to guess the service name correctly. With each incorrect guess, another part of the hangman is drawn. Guess correctly, and you'll earn
a point. After completing 10 rounds, you'll see your final score.

Code Breakdown

Let's look at the key components of the code to understand how the game works:

1. Game Structure

The game is built using object-oriented programming with two main classes:
• Button: Handles all interactive buttons in the game
• Hangman: The main game class that manages game states and logic

class Button:
    def __init__(self, x, y, width, height, text, color, hover_color, text_color=BLACK, font=font):
        # Button initialization code

    def draw(self, surface):
        # Draw the button on the screen

    def check_hover(self, pos):
        # Check if mouse is hovering over button

    def is_clicked(self, pos, event):
        # Check if button is clicked
Enter fullscreen mode Exit fullscreen mode

2. AWS Service Categories

The game uses a dictionary structure to organize AWS services by category:

word_categories = {
    "AWS Compute": ["EC2", "LAMBDA", "FARGATE", "LIGHTSAIL", "BEANSTALK", ...],
    "AWS Storage": ["S3", "EBS", "EFS", "FSX", "GLACIER", ...],
    "AWS Database": ["RDS", "DYNAMODB", "AURORA", "REDSHIFT", ...],
    # More categories...
}
Enter fullscreen mode Exit fullscreen mode

This makes it easy to add new services or entire categories through the custom_words.py file.

3. Game States

The game uses a state machine pattern to manage different screens:

def run(self):
    # Game loop
    while running:
        # Handle events based on game state
        if self.game_state == "menu":
            # Menu screen logic
        elif self.game_state == "category_select":
            # Category selection logic
        elif self.game_state == "playing":
            # Gameplay logic
        elif self.game_state == "game_over":
            # Game over screen logic

        # Draw the appropriate screen
        if self.game_state == "menu":
            self.draw_menu()
        elif self.game_state == "category_select":
            self.draw_category_select()
        # And so on...
Enter fullscreen mode Exit fullscreen mode

This approach makes the code modular and easier to maintain.

4. Background Image Handling

The game loads a background image from the local images folder:

# Load background image from local file
images_dir = os.path.join(os.path.dirname(__file__), "images")
bg_path = os.path.join(images_dir, "aws_bg.jpg")
if os.path.exists(bg_path):
    background_images["main"] = pygame.image.load(bg_path)
    background_images["main"] = pygame.transform.scale(background_images["main"],(SCREEN_WIDTH, SCREEN_HEIGHT))
Enter fullscreen mode Exit fullscreen mode

A semi-transparent overlay is added to ensure text remains readable:

# Create a semi-transparent overlay for better text readability
overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
overlay.fill((255, 255, 255, 180))  # White with 70% opacity
Enter fullscreen mode Exit fullscreen mode

5. Drawing the Hangman

The hangman drawing is created step by step as the player makes incorrect guesses:

def draw_hangman(self):
    # Base
    pygame.draw.line(screen, BLACK, (150, 350), (250, 350), 5)

    # Pole
    if self.wrong_guesses >= 1:
        pygame.draw.line(screen, BLACK, (200, 350), (200, 100), 5)

    # Top beam
    if self.wrong_guesses >= 2:
        pygame.draw.line(screen, BLACK, (200, 100), (300, 100), 5)

    # And so on for each part of the hangman...
Enter fullscreen mode Exit fullscreen mode

Educational Value

Beyond being a fun game, this project serves several educational purposes:

  1. AWS Service Familiarity: Players naturally memorize AWS service names through repeated gameplay
  2. Python Programming: The code demonstrates object-oriented programming, state machines, and event handling
  3. Pygame Framework: Shows how to build interactive games with Pygame
  4. UI/UX Design: Implements a clean, intuitive interface with proper feedback

Customization Options

The game is designed to be easily customizable:

Add New AWS Services: Edit the custom_words.py file to add more services.
Change Background: Replace the aws_bg.jpg file in the images folder.
Add Sound Effects: Place MP3 files in the sounds folder for audio feedback.

Conclusion

Building this AWS Cloud Services Hangman game was both fun and educational. It demonstrates how gaming mechanics can be used to make learning technical content more engaging. The modular code structure makes it easy to extend with new features or customize for different learning objectives.

What's truly remarkable is how Amazon Q made the development process incredibly streamlined. As an AI assistant, Amazon Q helped me rapidly prototype the game, debug issues, and implement new features with minimal effort. When I encountered challenges like adding background images or fixing button spacing, Amazon Q provided immediate solutions with clear explanations.

The collaborative development experience with Amazon Q transformed what could have been a complex coding project into an accessible and enjoyable process. Even developers with limited game development experience can leverage Amazon Q to build educational games like this one, receiving guidance on everything from Pygame fundamentals to AWS-specific implementations.

Whether you're studying for AWS certifications or just want to become more familiar with cloud services, this game provides an entertaining way to reinforce your knowledge. And with Amazon Q as your coding partner, creating your own educational games becomes an achievable goal for developers at any skill level.


The complete source code is available on GitHub, along with installation instructions and more detailed documentation. Happy coding and happy AWS learning!

Top comments (0)