The instruction file is attached. The library we should be using is Zelle.
Unformatted Attachment Preview
The Project Description: Pete-A-Maze
We are celebrating its 150th anniversary and in honor of the occasion, you have been asked to develop a new
game, the Pete-A-Maze. Players attempt to complete a maze in the least number of moves, crossing as few
tripwires as possible. Pete-A-Maze tracks the players’ names, moves and scores and displays the Top Scores.
The Game Panel: Do you want to play a game?
Pete-A-Maze starts by displaying the Game Panel, a 300×200 Graphics window as shown below which has
controls that change based on user input. Initially, the Game Panel includes the Pete-A-Maze title, top 4 scores,
and an option to either start a new game or exit the program.
Pete – A – Maze
Initial Game Panel
Pete – A – Maze
Pete – A – Maze
Game Panel after clicking NEW PLAYER
Game Panel during game play
When the user clicks on NEW PLAYER, the NEW PLAYER label is replaced by START! and the top scores area
of the Game Panel is undrawn and replaced with an Entry box labeled Player Name:
During game play, the START! label is replaced by NEW PLAYER, the player’s name and current score are shown
and a new yellow control area labeled RESET is available.
The Field: Where Pete lives and plays
When a new game starts, the Field is drawn using a 400 x 400 Graphics
window with a white background and a 10 x 10 grid of light-grey lines. Each
grid is a 40×40 pixel square. The top-left grid is filled with green and the
bottom-right corner is red.
To play the game, the user controls Pete who is represented by a 36×36
gold square in the upper-left corner of the grid. The objective of the game is
to navigate from the upper left hand corner to the lower right hand corner in
as few moves as possible. The player’s score is based on the number of
moves it takes for Pete to reach the objective.
Pete can be moved only one grid at a time, either horizontally or vertically
by clicking in any open grid in the same row or column. Pete cannot move
diagonally, only up, down, right or left one grid.
A click in his row moves Pete right or left
A click in his column moves him up or down
The Grid and Pete at the start
Pete reached the red square — Game Over!
The Sensors: Prepare to Amaze!
Pete-A-Maze is challenging due to a series of sensors drawn on the grid. Each vertical and horizontal grid
border has a 40% chance of including a sensor. As the player moves Pete through the grid, if he crosses one
of these sensors it counts as three (3) moves in the player’s score instead of one. The sensors are represented
by a narrow, 5×36 orange Rectangle drawn on the grid border and each border has a 40% chance of including
a sensor. Some examples of a Pete-A-Maze grid are shown below.
Page 2 of 6
About the Project: The Tasks
In this project, you will complete several tasks:
1. Setup your python file
2. The panel Graphics window
3. The field Graphics window
4. Animating Pete
5. Start to finish
6. Border crossings
7. Getting sensitive
8. Scoring the game
9. Top 4 scores
TODO #1: Set up your python file
The Python program file should be setup with the following guidelines:
• All library import statements should be at the top of the file
• File includes a header describing program, its purpose and function
• Header includes your name, the program name and a description of its function
• All Python code should be contained within function definitions with the exception of:
• Library import commands
• Header comments
• Function definition statements themselves — i.e. def main():
• The main() statement which starts the program
TODO #2: The Game Panel Graphics window
Write a separate Python function that creates a 300 x 200 Graphics window and all the required graphics
objects to create the Game Panel shown in the project description. You may rearrange the component groups
if you choose, but they must all still be included. For this part of Project 2, focus on creating and drawing
Graphic objects for the initial state of the Game Panel first, then work on the components for the additional
The Pete-A-Maze title and EXIT control should be displayed at all times. If a mouse click is detected on the
EXIT control at any time, (whether a game is active or not), the program should close all Graphics windows
and terminate. The following table clarifies the Game Panel components that should be displayed. This
function should return all of the graphics objects created.
Game Panel Components Displayed
Initial state at program start, no active game
Top 4 scores Text area and NEW PLAYER control
If NEW PLAYER clicked
NEW PLAYER control label is changed to START!,
Player Name: Text label and Entry box
Game is active if START! clicked and
Player Name: is not empty/blank
RESET and NEW PLAYER, player name and current,
players score Text objects
Game is over
Top 4 scores Text area, NEW PLAYER and RESET controls
HINT: You can create graphics objects and then choose when to .draw() or .undraw() them as needed.
Page 3 of 6
TODO #3: The Field Graphics window
Write a separate Python function that creates The Field and Pete as defined in the program description.
This Graphics window must match the specified design precisely.
This function should perform the following tasks:
Define a 400 x 400 pixel Graphics window with a white background
Draw 10 x 10 grid pattern filling the Graphics window — each grid is a 40×40 pixels with a light-grey outline
Draw a 40×40 green Rectangle with a light-grey outline in the top-left grid
Draw a 40×40 red Rectangle with a light-grey outline in the bottom-right grid
Draw Pete, a 36×36 gold Rectangle centered in the top-left grid
Return the Field and Pete objects
TODO #4: Animating Pete
Write a separate Python function that enables the user to move Pete around the Field grid. Use the
following to help determine the operation of this function:
If a mouse click is detected in the same grid row as Pete, move one grid horizontally towards the click
If a mouse click is detected in the same grid column as Pete, move one grid vertically towards the click
Mouse clicks detected other than in the same grid row or column as Pete are ignored
Mouse clicks detected in the same cell as Pete are also ignored
HINT: Mouse clicks anywhere in the same grid row or column as Pete should cause him to move.
TODO #5: Start to finish
The objective of the game is to navigate Pete from the upper left (green) to the lower right (red) cell in the grid.
Modify the function that enables Pete to move to meet the following requirements:
1. If Pete is in the same cell as the red Rectangle (the bottom-right grid) the game is over
2. When the game is over, draw a Text object containing the String Finished! Click to Close
centered in the Field Graphics window
3. When the game is over, a click anywhere in the grid should close the Field window
TODO #6: Border crossings
It is important to track movements in the Field Graphics window. Specifically, your program must detect which
border Pete crosses with each movement. You may use any technique for this portion of the Project – however
one approach is described here:
An example 4×4 grid
Think of the Graphics window as a grid with each column and row represented by
letters – in this example, the columns are A,B,C and D and rows are a,b,c and d.
Across each row (and down each column), number each border starting at 1
For this example, the borders would be identified as follows:
o A1 – the first horizontal border in column A
o b1 – the first vertical border in row b
o C3 – the third horizontal border in column C
o d2 – the second vertical border in row d
Keep track of the number of times Pete moves, and which border is crossed with
each movement. This will be used in TODO #8: Scoring the game
Note: Your Field Graphics window will be a 10×10 grid
Page 4 of 6
TODO #7: Getting sensitive
Each border has a 40% chance (4-in-10) of including a sensor represented by a narrow orange band as shown
in the project description. Write a separate function that completes the following tasks:
Loop through each column and randomly decide whether to draw a 36×5 horizontal orange Rectangle
Loop through each row and randomly decide whether to draw a 5×36 vertical orange Rectangle
Define a List including the border locations where an orange sensor Rectangle was drawn
Return the List of sensor locations
Modify the function that creates the Field Graphics window to create the sensors
TODO #8: Scoring the game
Calculate the game score by counting the total number of moves necessary for Pete to reach the lower right
(red) grid. Moving across a border where a sensor is drawn counts as three (3) moves. Modify the function that
enables Pete to move to meet the following requirements:
Add one (1) to the game score when Pete moves
Add three (3) to the game score when Pete moves across an orange sensor
Display the game score in the Game Panel as shown in the project description
Update the score every time Pete is moved
HINT: Compare the border crossing you determined in TODO #6 with the List of sensor locations returned by
the function in TODO #7.
TODO #9: Saving and displaying the top 4 scores
In TODO #2, you designed the Game Panel which displays the top 4 scores. These are read from a data file
named top_scores.txt which can be downloaded from the Project 2 assignment on Blackboard. Modify your
program to perform the following tasks:
1. Write a separate function named scoresOut() that updates the data file top_scores.txt to include
the score from the most recent game
2. The scoresOut() function should add the most recent score, but not remove any of the existing
scores in the file
3. The scoresOut() function should not return any values
4. Write a separate function named scoresIn() that reads the data file top_scores.txt and stores
the values in a List
5. The scoresIn() function should return only the lowest four (4) scores from the List
6. Modify the function that creates and updates the Game Panel window to to use the List returned by
scoresIn() to create the Text object in the top 4 scores panel
7. Modify your program so that when a game ends (TODO #5) the scoresOut() function is called and
the player name and score from the most recent game is written to the top_scores.txt data file.
NOTE: The objective of the game is to make the least number of moves. Lower scores are the best scores.
Page 5 of 6
Page 6 of 6
Purchase answer to see full