Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

and print scores like this Vo LTE Project 2 - Spring 2019.pdf CS 177 Spring 2019 Project #2 Due Date This assignment is due by

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

and print scores like this

image text in transcribed

Vo LTE Project 2 - Spring 2019.pdf CS 177 Spring 2019 Project #2 Due Date This assignment is due by 11:59 pm on Monday, April 1 Submit it to the Project 2 assignment on Blackboard Late submissions will receive a 50% grade deduction .You may submit up to 3 times NOTE: Read the entire Project 2 document before starting this assignment The Project Description: Pete-A-Maze Purdue is celebrating its 150 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 300x200 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. d Game Panel Game Panel Pete-A-Maze Pete-A-Maze Pete-A-Maze Player Name: Player Name: BigMac Dig Mac 21 Score: 7 RE intal Game Panel Game Panel after clcking NEW PLAYER Game Panel duning game play When the user clicks on NEW FLAYER, the NEW PLAYER label is replaced by STARTand the top scores area of the Game Panel is undrawn and replaced with an Entry box labeled Player Name: During game play, the STARI! 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. CS 177-Project #2 Spring 2019 The Field: Where and Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 lives and pl 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 40x40 pixel square. The top-left grid is filled with green and the bottom-right corner is red. To play the game, the user controls Fete who is represented by a 36x36 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. The Grid and Pete at the stard A ciek in his row movea Pete night or A click in his columm moves is up or dow 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 trough 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, 5x36 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 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 About the Project: The Tasks In this project, you will complete several tasks: 1. Setup your project2.py 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: Setu The Python program file should be setup with the following guidelines ur project2py file File name is project2.py 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 .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 Fanel 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 program states 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 Fanel components that should be displayed. This function should return all of the graphics abjects created. Program State Initial state at program start, no active game Top 4 scores Text area and NEW PLAYER control If NEW PLAYER clicked Game Panel Components Displayed Game is active if START! clicked and Player Name: is not empty/blank Game is over NEW PLAYER control label is changed to START! Player Name: Text label and Entry box RESET and NEW PLAYER, player name and current, players score Text objects 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 of6 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 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: 1. Define a 400 x 400 pixel Graphics window with a white background 2. Draw 10 x 10 grid pattern filling the Graphics window each grid is a 40x40 pixels with a light-grey outline 3. Draw a 40x40 green Rectangle with a light-grey outline in the top-left grid 4. Draw a 40x40 red Rectangle with a light-grey outline in the bottom-right grid 5. Draw Pete, a 36x36 gold Rectangle centered in the top-left grid 6. Return the Field and Fete 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: 1. If a mouse click is detected in the same grid row as Pete, move one grid horizontally towards the click 2. If a mouse click is detected in the same grid column as Pete, move one grid vertically towards the click 3. Mouse clicks detected other than in the same grid row or column as Pete are ignored 4. 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 Fete 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 Fete 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 cose 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 Fete crosses with each movement. You may use any technique for this portion of the Project- however one approach is described here: A B C D 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 bl-the first vertical border in row b o C3-the third horizontal border in column c d2 - the second vertical border in row d Keep track of the number of times Pete moves each movement. This will be used in TODO #8: Scoring the game with * An example 4xd grid Note: Your Field Graphics window wil be a 10x10 grid Page 4 of 6 177-Prniect # 2019 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 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: 1. 2. 3. 4. 5. Loop through each column and randomly decide whether to draw a 36x5 horizontal orange Rectangle Loop through each row and randomly decide whether to draw a 5x36 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: 1. Add one (1) to the game score when Fete moves 2. Add three (3) to the game score when Fete moves across an orange sensor 3. Display the game score in the Game Fanel as shown in the project description 4. 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 displa 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: the top 4 scores 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 scoresutfunction 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 scores In 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 Modify your program so that when a game ends (TODO #5) the score sout the player name and score from the most recent game is written to the top scores.txt data file 7. function is called and NOTE: The objective of the game is to make the least number of moves. Lower scores are the best scores Upload your completed file (project2.py) to Blackboard by the due date .This assignment is due by 11:59 pm on Monday, April 1 * Late submissions will receive a 50% grade deduction .You may submit your Project 2 assignment up to 3 times Page 5 of6 Open With Print Vo LTE top_scores.txt BigMac,20 T.J.,22 BigMac,27 Hammer Down,31 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177 Spring 2019 Project #2 Due Date This assignment is due by 11:59 pm on Monday, April 1 Submit it to the Project 2 assignment on Blackboard Late submissions will receive a 50% grade deduction .You may submit up to 3 times NOTE: Read the entire Project 2 document before starting this assignment The Project Description: Pete-A-Maze Purdue is celebrating its 150 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 300x200 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. d Game Panel Game Panel Pete-A-Maze Pete-A-Maze Pete-A-Maze Player Name: Player Name: BigMac Dig Mac 21 Score: 7 RE intal Game Panel Game Panel after clcking NEW PLAYER Game Panel duning game play When the user clicks on NEW FLAYER, the NEW PLAYER label is replaced by STARTand the top scores area of the Game Panel is undrawn and replaced with an Entry box labeled Player Name: During game play, the STARI! 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. CS 177-Project #2 Spring 2019 The Field: Where and Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 lives and pl 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 40x40 pixel square. The top-left grid is filled with green and the bottom-right corner is red. To play the game, the user controls Fete who is represented by a 36x36 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. The Grid and Pete at the stard A ciek in his row movea Pete night or A click in his columm moves is up or dow 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 trough 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, 5x36 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 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 About the Project: The Tasks In this project, you will complete several tasks: 1. Setup your project2.py 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: Setu The Python program file should be setup with the following guidelines ur project2py file File name is project2.py 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 .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 Fanel 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 program states 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 Fanel components that should be displayed. This function should return all of the graphics abjects created. Program State Initial state at program start, no active game Top 4 scores Text area and NEW PLAYER control If NEW PLAYER clicked Game Panel Components Displayed Game is active if START! clicked and Player Name: is not empty/blank Game is over NEW PLAYER control label is changed to START! Player Name: Text label and Entry box RESET and NEW PLAYER, player name and current, players score Text objects 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 of6 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 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: 1. Define a 400 x 400 pixel Graphics window with a white background 2. Draw 10 x 10 grid pattern filling the Graphics window each grid is a 40x40 pixels with a light-grey outline 3. Draw a 40x40 green Rectangle with a light-grey outline in the top-left grid 4. Draw a 40x40 red Rectangle with a light-grey outline in the bottom-right grid 5. Draw Pete, a 36x36 gold Rectangle centered in the top-left grid 6. Return the Field and Fete 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: 1. If a mouse click is detected in the same grid row as Pete, move one grid horizontally towards the click 2. If a mouse click is detected in the same grid column as Pete, move one grid vertically towards the click 3. Mouse clicks detected other than in the same grid row or column as Pete are ignored 4. 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 Fete 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 Fete 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 cose 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 Fete crosses with each movement. You may use any technique for this portion of the Project- however one approach is described here: A B C D 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 bl-the first vertical border in row b o C3-the third horizontal border in column c d2 - the second vertical border in row d Keep track of the number of times Pete moves each movement. This will be used in TODO #8: Scoring the game with * An example 4xd grid Note: Your Field Graphics window wil be a 10x10 grid Page 4 of 6 177-Prniect # 2019 Open With Print Vo LTE Project 2 - Spring 2019.pdf CS 177-Project #2 Spring 2019 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: 1. 2. 3. 4. 5. Loop through each column and randomly decide whether to draw a 36x5 horizontal orange Rectangle Loop through each row and randomly decide whether to draw a 5x36 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: 1. Add one (1) to the game score when Fete moves 2. Add three (3) to the game score when Fete moves across an orange sensor 3. Display the game score in the Game Fanel as shown in the project description 4. 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 displa 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: the top 4 scores 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 scoresutfunction 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 scores In 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 Modify your program so that when a game ends (TODO #5) the score sout the player name and score from the most recent game is written to the top scores.txt data file 7. function is called and NOTE: The objective of the game is to make the least number of moves. Lower scores are the best scores Upload your completed file (project2.py) to Blackboard by the due date .This assignment is due by 11:59 pm on Monday, April 1 * Late submissions will receive a 50% grade deduction .You may submit your Project 2 assignment up to 3 times Page 5 of6 Open With Print Vo LTE top_scores.txt BigMac,20 T.J.,22 BigMac,27 Hammer Down,31 Open With Print

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions