Assignment 8: Image Puzzle Game with Azure Integration
Interact with the Azure DALLE image generation API from the command line to generate a puzzle image.
Use a custom data structure to represent and manage puzzle pieces.
Implement GUI gameplay (using the big-bang style library) to let the player unscramble a scrambled image by rotating and swapping pieces until they match their correct orientation and position.
Instructions
Due Date: Both parts due Tuesday, December 17 18, 10:00 pm
1 Overview
Putting together puzzles is a great pasttime. You get to put together
a picture, presumably of something that interests you. The unfortunate
thing is, you always know exactly what the picture is supposed
to look like—
In this project, you will create a simple puzzle game. This game should be launched from the command line. You should invoke ./puzzle (or ./puzzle.exe on Windows for those who wish) to execute your program, and that alone should do everything necessary.
The user will be prompted to enter a text description (prompt) of an image. The user can type until entering a newline, which signals the end of the prompt. The system will send this prompt to the Azure image generation service DALL·E to obtain a corresponding image (I do, specifically mean Azure this time). If the system call rejects the prompt or does not return an image, your program should tell the user and ask again for another image generation prompt.
Once the image is successfully generated, the program transition to a graphical mode (using the big-bang library).
The user will see a scrambled version of the generated image. The goal is to reassemble the image into its correct configuration. Note the image must be a square for this to work, so somehow crop your generated image to a square, or pad the sides.
The image will be split into \(n \times m\) pieces.
Pieces are placed in a grid but in random positions.
Each piece may also be rotated (90°, 180°, 270°) or flipped.
2 Gameplay Mechanics
Initially, the puzzle is scrambled:
Selecting a piece with a mouse click.
Pressing a key to rotate that piece left (L), right (R), or flip it (F), adjusting its orientation by 90°, 270°, or 180° as appropriate.
Alternatively, if a piece is already selected, the player can click on a second piece to swap their positions.
The puzzle is solved when all pieces are in their correct original position and orientation.
3 Details and Requirements
3.1 Pre-Game Setup (CLI Phase)
The program begins in the command line (no GUI yet). The user will be repeatedly asked to enter a textual prompt describing an image. For example, they might type:
"a serene landscape with mountains and a small house" |
Your program sends this prompt to the Azure image generation API. If the call fails or no image is returned, the program prompts the user again. Once a valid image is obtained, it is stored locally and loaded into the game.
3.2 Puzzle Initialization (Model)
You must come up with your own design to store and manage the puzzle pieces. For example, you might use a 2D array or a list of lists representing each grid position, or a HashMap. Perhaps each cell contains a Piece object. Regardless, the pieces need to know
Its correct position (row and column).
Its current orientation (0°, 90°, 180°, 270°).
Its current position on the board (which may differ from the correct position at the start).
You must write code to:
Split the generated image into \(n \times m\) pieces.
Randomize their placement and orientation.
Provide methods to rotate and swap pieces.
Your data structure and model code should be thoroughly tested. You will also implement a method to check whether the puzzle is solved.
3.3 GUI Interaction (Big-Bang Phase)
After preparing the puzzle, the command-line phase ends and the big-bang GUI starts. The GUI should:
Display the board with the scrambled pieces.
Allow the user to select pieces by clicking.
On key presses (L, R, F), rotate/flip the selected piece.
On clicking a second piece after one is selected, swap their positions.
Continuously check if the puzzle is solved. If it is, display a congratulatory message and end the game.
3.4 Azure Integration (Service Layer)
You will need to perform the following:
Reads an API key and endpoint configuration from a file or environment variables.
Sends the user’s prompt to the Azure image generation service.
Receives and parses the JSON response.
Downloads the generated image.
You should handle potential errors gracefully, and prompt the user again if image generation fails.
4 Implementation order
4.1 Part 1 (Model and Testing)
For Part 1, you should:
Implement the puzzle model and data structures.
Write thorough unit tests to ensure that rotations, flips, and swaps work correctly.
Have a mock or placeholder image (locally provided) to test the slicing into pieces.
Implement the solved-state checking logic.
4.2 Part 2 (Integration and GUI)
For Part 2, you will:
Integrate the Azure image generation call in the CLI phase.
Once an image is successfully generated, load and scramble the puzzle.
Start the GUI and implement all user interactions.
Confirm the game works end-to-end with a user-provided prompt.
5 Extra Credit (Optional)
Consider adding features such as:
Allowing the user to pick different puzzle sizes (e.g., 4x4, 5x5).
Adding a timer and displaying how long the user took to solve the puzzle.
6 Testing and Submission
Submit your code, tests, and instructions to the Assignment 8 Dropbox by the due date and time, and then you (and your partner, if you have one) should schedule a meeting with me. You should be prepared to demonstrate to me that you can invoke ./puzzle (or ./puzzle.exe on Windows for those who wish) to execute your program, and that alone should do everything necessary, and to demonstrate to me your knowledge of the program you have written and show me your tests and project infrastructure. As always, be very careful with your naming conventions.
7 Scheduling
You can go ahead and schedule your code walk with me using the following: