python代写

CS 177

Fall 2018

Project 2

Due Date:

This project is an individual assignment – you should complete it on your own, without help or assistance from others even if they are not taking CS 177. Submit your completed program to the Project 2 assignment on Blackboard by 11:59 pm, Friday November 9th.

Problem Description: Boiler Gold Hunt!

You have been asked to create a game called Boiler Gold Hunt where the player has to search for a single gold Circle hidden within a 15 x 15 grid of black Circles with a radius of 15. The game is played in 5 rounds and the player attempts to find five (5) gold Circles (one in each round). The player’s final score is the total number of clicks it takes to find all five hidden, gold Circles. The game must be written in Python, use only the graphic objects available in the Graphics library and allow the player to interact with the game using the mouse. The program must include a game control panel allowing users to enter their name, start a new game and exit the program. Player’s scores and statistics must be tracked in a text file named scores.txt

Players begin by entering their name in the PLAYER NAME box and clicking on the NEW GAME control in the control panel. At any time, even in the middle of a current game, players can reset the board and start a new game by clicking the NEW GAME control. They can also change the current player name.

At the start of each round, the program determines a random location for the hidden, gold Circle and displays a 15×15 grid of black Circles representing the game board. Clicking on any black Circle will reveal its hidden color (white, grey, tan or gold) which gives the player a clue to finding the hidden gold Circle. (You can see a demonstration of the game in the Project 2 video posted on Blackboard)

The hidden color assigned to a given Circle depends on it’s distance from the hidden gold Circle

Color Distance from the Gold Circle white 3 or more
grey 2 away
tan 1 away

Note: While each Circle is assigned a color at the beginning of a round, it is actually drawn with a black fill and the hidden color is revealed when it is clicked.

A Round ends when the gold Circle is found and the game ends after five Rounds. At the end of each game, the player’s name and score (total number of clicks) are stored in the scores.txt file which contains the names of previous players and their scores. This file should be sorted in ascending order, ie: lowest number of clicks first — highest number of clicks last.

This is an individual assignment – complete it on your own.

Page 1 of 5

Part1: Setupyourproject2.pyPythonprogramfile
Start a new Python program file that meets the following parameters:

• The filename must be project2.py
• Include a header with your name, the program name and a short description of its functionality • Import the Graphics library and any other libraries you will need
• The project2.py program must include pseudo code (comments) throughout the program

describing each function, section of code and logical decision.

Part 2: Create the Game Control Panel

Write a new function that completes the following tasks:

  • Create a 250 x 200 Graphics window with a light-grey

    background titled Game Control

  • Using Rectangles, Entry, Text objects and any other

    Graphics elements you need, create the elements in the Game Control Graphics window as shown in the example

    • The gold BOILER GOLD HUNT! title text is bold and in all capital letters
    • The NEW GAME and EXIT controls are Rectangles
    • NEW GAME (gold), EXIT (black)
    • The PLAYER NAME control is a white filled Entry box
    • The Text objects should be drawn using the size, color and font shown
  • The Game Control window should match the colors, font sizes and design shown
  • This function should return the Player Name, New Game, Exit and Game Control

    Graphics window objects.

    Part 3: Create the Boiler Gold Hunt Window

    Write a new function that completes the following tasks:

  • Create a 480×520 Graphics window titled GoldHunt
  • Draw a 480×40 black Rectangle at the top of the GoldHunt window as shown in the example
  • Create the Round and Clicks Text objects as shown in the example
  • This function should return the Round, Clicks and GoldHunt Graphics window objects

    This is an individual assignment – complete it on your own

Page 2 of 5

Part4: Createthemain()function
Write a function named main() that completes the following tasks:

  • Call the function that creates the Game Control graphics window – don’t forget to assign the Graphics objects it returns to variables
  • Call the function that creates the GoldHunt graphics window assigning the Graphics objects it returns to variables
  • Using a while loop, the main() function should repeat until a mouse click is detected on the EXIT control in the Game Control graphics window
  • After the while loop ends, close all graphics windows
    Test your main() function to verify that it operates correctly, closes the Graphics windows when EXIT is

    clicked and there are no error messages.

    Part 5: Create the Circle grid in the GoldHunt window
    Write a function using Lists and Circle objects that completes the following tasks:

  • Display the current PLAYER NAME (bold, gold Text) at the center of the top black border
  • Creates a 15×15 grid of black-filled Circles in the GoldHunt graphics window as shown below
  • Stores the black Circles as elements in a List
  • Create a List assigning each Circle a fill color that will be revealed after the Circle is clicked

• One Circle at random is assigned gold fill color
• Assign tan fill color to Circles next to the gold Circle • Assign grey fill color If they are two away from the

gold Circle
• Assign a white fill color to Circles that are more than

two away from the gold Circle
• Return the Lists containing the Circles and color assignments

The Circle grid at the start of a round

“Hidden” Circle color assignments

This is an individual assignment – complete it on your own

Page 3 of 5

Part 6: Enable game play!

Modify the main() function and write any other necessary functions to enable game play. A detailed description of the game play and rules follow here:

  • Players must enter a name and click the NEW GAME control to start a game
  • The NEW GAME control should only function if the PLAYER NAME Entry box is not empty
  • When the NEW GAME control is clicked and at the start of every Round, a 15×15 grid of black Circles (radius 15) is displayed in the GoldHunt graphics window (see below)
  • The black banner at the top of the GoldHunt graphics window displays the player’s name, the current Round number and the total number of Clicks in the current game
  • The Round number and Clicks start at 0 and increase as the game progresses
  • A game includes a total of five (5) Rounds
  • Clicks on a black Circle will reveal its assigned “hidden”

    color (white, tan, grey or gold).

  • A Round ends when the gold Circle is found
  • At the end of a Round, all Circles except for the gold are animated, appearing to fall from the GoldHunt graphics window before a congratulatory message is displayed
  • At the end of the game, the player’s score is the total number of clicks it took for them to find the gold Circle in all five (5) rounds
  • After five (5) rounds, the player’s name and total number of clicks are saved in the scores.txt file
  • The scores.txt file should be sorted by number of
    clicks in ascending order (ie: lowest to highest number of clicks)
  • A sample scores.txt file is provided with the Project 2 assignment and can be used with your program
  • A player can start a NEW GAME at any time even while a game is in progress
  • If the NEW GAME control is clicked, (and the PLAYER NAME control is not empty), any game in

    progress will end immediately and a new one begin without saving the current score

  • The program can be terminated by clicking the EXIT control at any time, even while a game is in progress
  • When the EXIT control is clicked, both Graphics windows should close without errors and the program should end

    The video shown with in Project 2 assignment on Blackboard should be helpful in understanding the game play process and requirements

    This is an individual assignment – complete it on your own

Page 4 of 5

Submit your completed project2.py Python program
Submit your completed program to the Project 2 assignment by 11:59 pm on Friday November 9th

Project 2 Grading Rubric Points

Part 1: Program has correct filename project2.py
Part 1: Program includes header with student name, the program name and a description
Part 1: Program is fully documented with comments for functions, decisions and functionality Part 2: Separate function creates Game Control Graphics window as specified
Part 2: Function creates all Graphics objects as shown
Part 2: Function returns all required Graphics objects
Part 3: Separate function creates GoldHunt Graphics window as specified
Part 3: Function creates all Graphics objects as shown
Part 3: Function returns all required Graphics objects
Part 4: main() function is defined
Part 4: main() function properly calls the function to create the Game Control window
Part 4: main() function properly calls the function to create the GoldHunt window
Part 4: main() function includes a while loop that ends when the EXIT control is clicked
Part 4: main() function closes all Graphics windows without errors
Part 5: Separate function creates a List of black Circles
Part 5: Function uses List to store “hidden” colors for the List of Circles
Part 5: Function randomly assigns gold to one Circle
Part 5: Function correctly assigns white, grey and tan colors to remaining Circles
Part 5: Function draws the black Circles in a 15×15 grid in the GoldHunt window
Part 5: Function returns the Lists of Circles and color assignments
Part 6: Players can click NEW GAME control to start over at any time (even during gameplay) Part 6: NEW GAME control works only when PLAYER NAME is not empty
Part 6: Black banner in GoldHunt window displays player name, round and number of clicks Part 6: Game ends after 5 rounds — Rounds end when gold Circle is revealed
Part 6: When Rounds end, Circles are animated as specified and message is displayed
Part 6: When game ends, players name and score are saved to scores.txt file as specified Part 6: Players can click EXIT control to quit at any time (even during gameplay)
Style / Format: Python code is formatted well, organized and easy to understand

5

 5
10
 5
10
 5
 5
10
 5
 5
 5
 5
 5
 5
10
 5
 5
10
 5
 5
 5
 5
 5
 5
10
10
 5
10

Total Points

180

This is an individual assignment – complete it on your own

Page 5 of 5