Description
In this lab we will be combining our efforts in top-down programming, where we deliberately organize and structure our code with main functions and sub functions, but will also add in our skills in Graphic User Interface (GUI). We continue to build abstraction – where a few small, simple and concrete tasks are packaged together to perform a more general task. The top-down approach helps us organize our code like an outline organizes our writing. Again, we start with an algorithm (chart), then translate it into pseudocode of comments and function name definitions.
In the last lab you created code to play Rock-Paper-Scissors. You will be working with the same code (modify to resolve comments from your last lab), but rather than using input() you will now collect input using the GUI. Be creative about displaying messages to the player.
Submittal to Turnitin.com
Because plagiarism in coding is dishonest, unethical, and is against the Miramonte Honesty Policy, you are required to submit your code to Turnitin.com. Make a Google Doc with your final code for Rock-Paper-Scissors and Word Jumble, and submit it to turnitin.com, Lab #8.
Problem #1 – Rock-Paper-Scissors Reprise (with GUI)
Game Requirements
- Display messages on the canvas that explain to the user how to choose Rock, Scissors, or Paper. They may not input their choice with any text input box.
- Once the player makes their selection, have the computer make a selection. Display both the player’s and computer’s selection on the Canvas (it is good programming practice to also display on the console to help you debug).
- Display the outcome (“You win!” or “Computer wins!”)
- Tally and update the score after each iteration of the game.
- You do not have to ask the user to play again… you can assume they will, but do give them some method to Quit when they are ready.
- When they quit, display a parting message and the final score.
RPS starter code
Rock-Paper-Scissors GUI starter code – copy/paste into Codeskulptor and build code. |
import simplegui import random “””Overview of Game Logic: #Global variables, changed within functions below # Canvas Dimensions ####### RPS algorithm helper functions ######## #Computer Generator #Determine Winner ########### EVENT HANDLERS ##################### # Player Choice Selection (not input box). def button_quit_handler(): # Handler to draw on canvas # Create a frame and assign callbacks to event handlers # Start the frame animation |
Insert Final, working Rock-Paper-Scissors with GUI code – include detailed comments |
<<your code here>> – please format with Code Blocks add-on – Python, github-gist
|
Problem 2: Word Jumble
As you solve a problem or write a computer program, the process should be:
- Understand the task/purpose of code
- Organize main task into sub-tasks and consider task flow (sequencing)
- Create flow structure with an algorithm flow chart (whiteboard!). Consider collaborating with a programming partner as you plan.
- Create pseudocode outline with comments, naming key flow functions.
- Build, code and test sub-functions first. Debug as you go. Revise plan/structure as necessary.
- Combine sub-functions into larger program and test, test, test! Revise plan as necessary.
- Consider extensions or improvements to original design.
Keep your words to 5 and 6 letters each. This is like the Jumble in the newspaper and online games and will make the GUI display easier and more aesthetically pleasing.
Overview
You need to create a program that allows a user to guess a word that has been jumbled together. This project focuses on Strings and String manipulation, as well as presenting output with the GUI.
Submission:
Note, this is modeled after the Create Performance Task that you will submit as part of your AP Portfolio. You will submit your code write up via Google Classroom and TurnItIn.com
Support Materials:
Development Process
Part 1: Backend Development
You will create a word jumble game. You should use functions to help you both pick a word from a list, scramble it and then prompt the user for guesses. Below is a rough outline of the pseudocode. You do NOT need to use this structure, but you SHOULD have some structure in place before you start writing code. Think of this as the outline.
Your first working version of the game will rely on input() and printing to the Console. We call this “Backend Development,” where we get the algorithm and flow working correctly.
Note, you may find the method, random.shuffle(some_list), to be helpful when scrambling the word. You will find the documentation in the Random Module
Optional Extension
Add a timer to your game. Give the user 30 seconds to guess the jumbled word.
The user is entering their guess in an input box.
Insert Word Jumble without GUI Algorithm (photo from whiteboard is fine, or use Google Draw algorithm) |
|
Insert Word Jumble without GUI Pseudocode here (outline of comments and function definitions that demonstrate intended flow) |
import random
word_list = [] def make_word_list(): #makes list of words def choose_word(): #random word from list def scramble_letters_in_word(): #shuffles letters of random word from list def display_scrambled_word(): #displays shuffled word def user_guess(text_input): #user input def check_if_correct(): #checks if correct/matches unshuffled word; if it does not match, asks again def play_jumble(): #starts jumble, asks if user wants to play def play_again(): #asks user to play again play_jumble() |
Insert Final, working Word Jumble without GUI code – include detailed comments |
import random
word_list = [] def make_word_list(): def choose_word(): def scramble_letters_in_word(): def display_scrambled_word(): def user_guess(text_input): def check_if_correct(): def play_jumble(): def play_again(): play_jumble() |
Part 2: Frontend Development
Once you have a working game using the input() and console, you will now modify it to include GUI.
You will create a GUI (similar to the one below). You should be able to use the majority of your code from part 1 for the underlying logic, however you may need some new variables and a draw handler to make the GUI display correctly. Remember all your print statements must be turned into variables that can be displayed on the canvas.
Here is some suggested code to include in your GUI version of the game.
# template for jumble with GUI import simplegui import random ###### INITIALIZATION CODE ################## ####### JUMBLE algorithm helper functions ######## ###### MAIN PROGRAM CALLED WHEN START BUTTON CLICKED #### ########### EVENT HANDLERS ##################### def text_input(): # this code will be similar to your userguess() function code in non-GUI def button_start_handler(): def button_exit_handler(): def draw(canvas): frame = simplegui.create_frame(‘Jumble’, 700, 500) frame.start() |
Insert Word Jumble with GUI Pseudocode here (outline of comments and function definitions that demonstrate intended flow – use the starter code but insert your functions to run the backend Jumble Algorithm) |
<<pseudocode here>>
|
Insert Final, working Word Jumble with GUI code – include detailed comments |
<<code here>> – please format with Code Blocks add-on – Python, github-gist
|