Lab 8: Memory Puzzle
A CS151 Game Reproduction
In this week's lab, we will start working on another game called Memory Puzzle. The game presents a grid of hidden numbers which overlay an image. The goal of the player is to match the numbered cells in the grid to make them disappear and view the image behind the grid. When a cell in the grid is clicked, its value is shown until the next click, making the game a good memory test.
The goals this week are:
I recommend that you start working on this project today. As always, let me know if you have any questions or if you need any help.
Create a Lab08 folder on your computer where you store CS151 projects and labs, hopefully somewhere that is backed up (e.g. in Dropbox, Google Drive, Microsoft One Drive, etc.)
Download the file memory_puzzle.py [HERE] ,copy it to your Lab08 folder, and open it in VS Code.
Download the image file Colby.gif [HERE] and copy it to your Lab08 folder.
Open up a Terminal (e.g. Control+` in VS Code) and change the directory (cd) to the Lab08 folder.
Read the code already in the file and make sure you understand it before you proceed. This is called Code Comprehension, and it is the most common activity in software development.
First, let’s make a game grid by implementing the make_grid(rows, cols): function. Read the function docstring to understand the intended job of the function. The function is expected to do the following:
Make sure this function works for a grid of any number of rows or columns. Test this function by printing the grid and inspecting it visually. Every value in the grid should appear twice.
Next, let’s implement the function draw_grid(grid, turt, x_pos, y_pos, tile_size, clicked=(-1, -1)) which draws the game grid on the turtle window. Inspect the function parameters and docstring to understand its intended job. The function is expected to do the following:
Test this function by drawing a grid and passing a specific clicked tuple representing a row and a column on the grid.
The play function is expected to be called every time there is a click on the window. The job of the function is to take click positions (X_pos, y_pos) and convert them to grid positions (row, column). In addition, the function handles the game logic when a cell is clicked by showing the cell and matching it to the last clicked cell. Therefore the function is expected to do the following:
The main function is expected to connect mouse clicks on the window to the play method, and update the window infinitely. In addition, you should count the number of clicks and display that on the screen every time the draw_grid method is called. This adds an element of competition to the game, where players try to solve the puzzle with the fewest number of clicks.
Here are a few ideas for project extensions:
current_time = time.time()