Word Guessing Game
Microsoft Word - Project 2 - Fall 2019.docx CS 177 Fall 2019 This is an individual assignment – complete it on your own. Page 1 of 6 Project 2 Due Date: This project is an individual assignment – you should complete it on your own, without help or assistance from anyone other than the CS 177 staff. Submit your completed program to the Project 2 assignment on Blackboard by 11:59 pm, Sunday November 3rd. Problem Description: Guess Master 2.0 You have been asked to enhance the game you created in Project 1 to create Guess Master 2.0. In this graphical version of the game, the player must still guess the letters in a random word selected from the words.txt file, however in each round when a player correctly guesses all the characters in a word, a new round begins and they have a new word to guess. Players earn points as they win each round. The program must be written in Python, using only the graphic objects available in the Python Graphics library, and must allow the player to continue playing until they choose to exit the game. The program must include a CONTROL PANEL graphics window providing two (2) controls: 1. NEW - Starts a new game 2. QUIT - Exits the program See figure 1 for an example of the CONTROL PANEL. Game Play A game begins when the player clicks the NEW control and ends when a player cannot guess a word within ten (10) tries. When the NEW control is clicked, the program opens the GAME PANEL Graphics window displaying a large BLOCK P and a series of black-filled Circles displaying the characters A to Z, (see figure 2 for an example). Above the BLOCK P are several Rectangles representing the number of letters in the secret word. When the player clicks the character Circle to guess a letter, incorrect guesses cause a piece of the BLOCK P to turn red and “fall away”, revealing their white-filled outline. Correct guesses will result in the letter appearing in the appropriate Rectangle above. As letters are guessed, the corresponding Circle fill color is changed to gold. In figure 2, the letters L, N, R, S and T have been guessed and three were incorrect causing three pieces of the BLOCK P to fall away. If the player successfully guesses all the letters in the word, the GAME PANEL , BLOCK P and Circle colors are reset and the player is given a new word with ten (10) guesses to reveal its characters. Figure 1 - the CONTROL PANEL Figure 2 - the GAME PANEL SCORE: 10 CS 177 Fall 2019 This is an individual assignment – complete it on your own. Page 2 of 6 Scoring the Game Each word to be guessed represents a “round” in the game. If the player guesses all the letters in a word, they’ve won that round and the game automatically chooses a new, random word and starts a new round. This continues until the player cannot reveal all the letters in a word before losing all ten (10) pieces of a BLOCK P. Players can earn up to 10 points in each round. Each incorrect letter guessed reduces their round score by 1 point. If after 10 guesses they have not guessed all the letters in the secret word, they lose the round and the game is over. An example of the scoring follows here: Round Secret Win or # Wrong Round Total Number Word Lose Guesses Score Score 1 RAIN Win 6 4 4 2 WAGON Win 5 5 9 3 SETTLE Win 8 2 11 4 DUTCH Lose 10 0 11 ß GAME OVER Scoring Example Explanation: This player played for four rounds. They correctly guessed the letters of the first three round secret words, (RAIN, WAGON and SETTLE) but did not correctly guess the word DUTCH in round four which ended the game. Players can earn up to 10 points in each round, with one point deduction for each incorrect guess. In this example the final score was 11. An important note: The NEW and QUIT controls in the CONTROL PANEL window will be functional at all times – even when a game is in progress. The player should be able to choose to continue playing their current game, start a new game or leave the program any time, at their own discretion. The program should be checking for and responding to clicks in either Graphics window. SCORE: 9 Figure 3 - A winning round CS 177 Fall 2019 This is an individual assignment – complete it on your own. Page 3 of 6 Part 1: Setup your project2.py Python program file 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 Control Panel Write a new function that completes the following tasks: • Creates a Graphics window with a light-grey background titled Welcome to: • Using Rectangles, Entry, Text objects and any other Graphics elements you need, create the elements in the CONTROL PANEL Graphics window as shown in the example • The gold GUESS MASTER 2.0 title text is bold, gold and in all capital letters • The NEW and QUIT controls are Rectangles • NEW (gold) and QUIT (black) • The CONTROL PANEL window Graphics objects should match the colors, font sizes and design shown in the example • HINT: The function should return the Graphics objects Part 3: Create the Game Panel Write a new function that completes the following tasks: • Create the GAME PANEL Graphics window titled Save the Block P with a gold background • Draw two rows of 13 black-filled Circles near the bottom of the GAME PANEL window as shown in the example below • Place a single white Text object within each of the 26 black Circles as shown in the example • Draw a series of 10 white-filled Polygons to create the BLOCK P shape as shown below • Draw a second series of black-filled Polygons creating the BLOCK P and covering the white Polygons. This allows the program to animate the black- filled shapes during gameplay, revealing their outlines • Using a technique similar to randomly Project 1, select a secret word from the words.txt datafile • Draw a series of gold-filled Rectangles representing the characters in the secret word (see figures 2 and 3) • HINT: Store the Circles, Polygons, Rectangles and Text objects in Lists. This will allow you to change their properties later • This function should return the Graphics objects and the secret word selected CS 177 Fall 2019 This is an individual assignment – complete it on your own. Page 4 of 6 Part 4: The drop() function Write a new function named drop() that accepts a Polygon object as an argument and completes the following tasks: • Change the fill color of the Polygon to red • Animate the Polygon to appear to “fall” down out of the Graphics window (HINT: Use a loop that moves the Polygon a few pixels at a time in the Y direction until it is no longer visible in the GAME PANEL Graphics window) • The drop() function does not return any values Part 5: Putting it all Together The program should start with the main() function and should follow this logical process: • Create the CONTROL PANEL Graphics window • Check for a click on the NEW or QUIT controls • If the QUIT control is clicked: • Close the CONTROL PANEL Graphics window • Program ends • If the NEW control is clicked, start a new game as described in Part 5: Playing the Game Part 6: Playing the Game All games start at round 1 and progress through multiple rounds until the player cannot correctly guess all the letters in the secret word. At the start of a round: • Create a new GAME PANEL Graphics window as described in Part 3 • If this is round 1, set the player’s score to 10 • If this is not round 1, add 10 points to the player’s score • Create a score Text object at the top of the GAME PANEL (see figures 2 and 3) and display the characters “SCORE: ” + the player’s current score • Check for clicks on the NEW or QUIT controls or any of the black “letter” Circles HINT: Use the .checkMouse() function • If QUIT control is clicked: § Close the CONTROL PANEL Graphics window § Close the GAME PANEL Graphics window § Program ends • If NEW control is clicked: § Close the GAME PANEL Graphics window § Set the player’s score to 0 and restart the game as shown in Part 5: Playing the Game • If a click is within one of the letter Circles: § Change the clicked Circle fill color to gold and the Text character color to black § Determine the character guessed (clicked) § Check for all occurrences of the guessed character in the secret word (HINT: This is similar to Project 1) § For all occurrences of the guessed character in the secret word, create it as a Text object within the appropriate gold Rectangle above the BLOCK P (see figures 2 and 3) § If the guessed character is not in the secret word: § Decrease the player’s score by 1 point and update the score Text object § Animate the loss of one of the BLOCK P Polygons using the drop() function CS 177 Fall 2019 This is an individual assignment – complete it on your own. Page 5 of 6 Part 7: Winning a Round If all the characters in