Adding GUI: Coding RPS and Word Jumble  Lab#8 Solved

30.00 $

Categories: ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (2 votes)

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

  1. 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.
  2. 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).
  3. Display the outcome (“You win!” or “Computer wins!”)
  4. Tally and update the score after each iteration of the game.
  5. 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.
  6. 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:
1.  Screen is drawn with blank values, input method for player RPS
is explained/presented
2.  Player selects R, P, or S using some form of
GUI input (no input box).
3.  Computer randomly selects option R, P or S
4.  Winner is identified, results shared, score updated and posted
5.  Repeats #2-4 each time a button, key-stroke, or mouse-click
is initiated.
4.  Stops when quit is pressed/clicked.
“””
###### INITIALIZATION CODE ##################

#Global variables, changed within functions below

# Canvas Dimensions
canvas_width =
canvas_height =

####### RPS algorithm helper functions ########

#Computer Generator
def comp_choice():
pass
“””Will randomly select Rock, Paper, or Scissors. “””
#global variables here.
#pick a random R, P, or S….
#Update computer choice message for draw handler
#call winner() to determine outcome

#Determine Winner
def winner():
pass
“””Determine the winner then updates the score”””
#global variables here
#determines the winner
#updates the necessary draw(canvas) variables to show messages

########### EVENT HANDLERS #####################
#define event handlers for mouse click, buttons, input box, key_strokes, draw

# Player Choice Selection (not input box).

def button_quit_handler():
pass
#global variable here
#updates the necessary draw(canvas) variables

# Handler to draw on canvas
def draw(canvas):
pass
#Player choice: use canvas.draw_text(parameters), pass in message as variable
#Computer choice
#Winner text and score update
#Any additional messaging

# Create a frame and assign callbacks to event handlers
frame = simplegui.create_frame(“Rock, Paper, Scissors”, canvas_width, canvas_height)
frame.add_label(‘Player Choice:  Select One’)
frame.add_button(#add parameters)
frame.set_draw_handler(#add parameter)
#add more frame.set for key handler, buttons, mouse click, etc.

# Start the frame animation
frame.start()

 

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:

  1. Understand the task/purpose of code
  2. Organize main task into sub-tasks and consider task flow (sequencing)
    1. Create flow structure with an algorithm flow chart (whiteboard!). Consider collaborating with a programming partner as you plan.
    2. Create pseudocode outline with comments, naming key flow functions.
  3. Build, code and test sub-functions first. Debug as you go. Revise plan/structure as necessary.
  4. Combine sub-functions into larger program and test, test, test! Revise plan as necessary.
  5. 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

Submission:

Development Process

Part 1:  Backend Development

Part 2: Frontend Development

 

 

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:

  1. Video of Frontend and Backend
  2. String randomizer

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 = []
word = “”
scram_list = []
scrambled_word = “”
users_guess = “”

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 = []
word = “”
scram_list = []
scrambled_word = “”
users_guess = “”
guesses= 0

def make_word_list():
global word_list
word_list = [“apple”, “gamer”, “chair”, “happy”]

def choose_word():
global word
word = “”
word = random.choice(word_list)

def scramble_letters_in_word():
global scram_list
scram_list = []
scram_list.extend(word)
random.shuffle(scram_list)

def display_scrambled_word():
global scrambled_word
scrambled_word = “”
for letter in scram_list:
scrambled_word = scrambled_word + letter
print (scrambled_word)

def user_guess(text_input):
global users_guess
users_guess = text_input
check_if_correct()

def check_if_correct():
global guesses
if word == users_guess:
guesses +=1
print (“You got it!”)
print (“Guesses: “, guesses)
print (“”)
play_again()
else:
guesses +=1
print (“You did not get it!”)
print (“Guesses: “, guesses)
user_guess(input(“Try again, unjumble the word!”))

def play_jumble():
play_game = input(“Do you want to play jumble?”)
if play_game[0].upper() == “Y”:
make_word_list()
choose_word()
scramble_letters_in_word()
display_scrambled_word()
user_guess(input(“Unjumble the word!”))
elif play_game[0].upper() == “N”:
print (“Thanks for playing.”)
else:
play_jumble()

def play_again():
global guesses
jumble_again = input(“Do you want to play again?”)
if jumble_again[0].upper() == “Y”:
guesses = 0
make_word_list()
choose_word()
scramble_letters_in_word()
display_scrambled_word()
user_guess(input(“Unjumble the word!”))
elif jumble_again[0].upper() == “N”:
print (“Thanks for playing.”)

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 ##################
# global variables some of these variables will initially be empty strings
# since they will not be displayed at the start of the game.

####### JUMBLE algorithm helper functions ########
# insert working algorithm code from your Backend design

###### MAIN PROGRAM CALLED WHEN START BUTTON CLICKED ####
def gameison():
# global variables
# reset the global variables at the start of each round – new scrambled word.
pass

########### EVENT HANDLERS #####################
#define event handlers for mouse click, buttons, input box, key_strokes, draw

def text_input():
# global variables

# this code will be similar to your userguess() function code in non-GUI
# jumble but the print statements will have to used to create global variables
# that are displayed on the canvas.

def button_start_handler():
# global variables
gameison()

def button_exit_handler():
# global variables
frame.stop()

def draw(canvas):
# remember this function is called 60 times a second.

frame = simplegui.create_frame(‘Jumble’, 700, 500)
frame.add_button(# add parameters for a start to play button)
frame.add_button (# add parameters for an end to play button)
frame.add_input(# add parameters for an input pox)
frame.set_draw_handler(# add parameter)

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

 

 

 

 

 

 

 

 

  • Lab8.zip