Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment #7: Rock Paper Scissors Summary: Create the Rock Paper Scissors progr

ID: 3849752 • Letter: A

Question

Assignment #7: Rock Paper Scissors

Summary: Create the Rock Paper Scissors program.

The solution file should be named RPS_ExerciseE.rb.

Use the instructions on page 290 of the textbook.

Run your program until it works and the output looks nice.

290 CHAPTER 8 Object-oriented Programming 17. A(n) variable's scope is accessible to all instances of the same class a. Local b. Global C. Instance Class 18. The d method determines whether a variabie exists, returning a value of true if the variable is found. 19. Using the method, you can reverse the onder in which arrays are retrieved. 20. s a keyword that can be used as a shorthand a way of referring to the current object. Reinforcement Exercises The following exercises are designed to further your understanding of Ruby programming by challenging you to make improvements tothe chapters game project, the Rock, Paper, Scissors game. 1. Currently, the Game class's get player move method uses a regular expression to validate the player's moves of Rock. Paper, or Scissors, rejecting any input other than one of these words. Making the player enter entire words takes time and can lead to typos, however. Simplify game play by modifying the get player move method to also allow single- character input in the form of R, P, and S. Make sure you accommodate both uppercase and lowercase input. 2. The game allows players to play an unlimited number of times. To help them keep track of how many times they have played, modify the game by adding a global variable named Sgamecount at the beginning of the program's Main Script Logic area, assigning it an initial value of 0. Next add a method named game count and set it to increment the value of sgamecoun t each time it is executed. Lastly, add a statement to the play game method that executes the

Explanation / Answer

from tkinter import *

from sys import *

from PIL import Image, ImageTk

import pygame as py

import os

from random import randrange

py.init()

def runGame(startWindow):

startWindow.destroy()

startWindow.quit()

master = Tk()

master.title('Lets Play!')

def carryGame(button_id):

    result = StringVar()

    printResult = Label(master, textvariable = result, font='Bizon 32 bold', bg='PeachPuff2')

    printResult.place(x=150, y=300)

    random_Num = randrange(1,4)

    if random_Num == 1:

       computer_Move = 'Rock'

    elif random_Num == 2:

        computer_Move = 'Paper'

    else:

        computer_Move = 'Scissors'

    if button_id == 1:

        player_Move = 'Rock'

    elif button_id == 2:

        player_Move = 'Paper'

    else:

        player_Move = 'Scissors'

rock_Button = Button(master, width=15, height=7, command=lambda:carryGame(1))

rock_photo=PhotoImage(file=r'C:UsersPamalDesktopDocumentsPython FolderPython ProjectsRock, Paper, ScissorsV 1.2Images ock.png')

rock_Button.config(image=rock_photo,width="120",height="120")

rock_Button.place(x=17, y=70)

paper_Button = Button(master, width=15, height=7, command=lambda:carryGame(2))

paper_photo=PhotoImage(file=r'C:UsersPamalDesktopDocumentsPython FolderPython ProjectsRock, Paper, ScissorsV 1.2Imagespaper.png')

paper_Button.config(image=paper_photo,width="120",height="120")

paper_Button.place(x=167, y=70)

scissors_Button = Button(master, width=15, height=7, command=lambda:carryGame(3))

scissors_photo=PhotoImage(file=r'C:UsersPamalDesktopDocumentsPython FolderPython ProjectsRock, Paper, ScissorsV 1.2Imagesscissors.png')

scissors_Button.config(image=scissors_photo,width="120",height="120")

scissors_Button.place(x=317, y=70)

label_1 = Label(master, text='Please make your selection-', font='Bizon 20 bold', bg='PeachPuff2')

label_1.pack(side=TOP)

label_2 = Label(master, text='The computer picked:', font='Helvetica 22 bold', bg='PeachPuff2')

label_2.place(x=70, y=240)

master.maxsize(450, 400)

master.minsize(450, 400)

master.config(background='PeachPuff2')

master.mainloop()

def startScreen():

    def playMusic(fileName):

        py.mixer.music.load(fileName)

        py.mixer.music.play()

    startWindow = Tk()

    startWindow.title('[Rock] [Paper] [Scissors]')

    load = Image.open(r'C:UsersPamalDesktopDocumentsPython FolderPython ProjectsRock, Paper, ScissorsV 1.2Images itle.png')

    render = ImageTk.PhotoImage(load)

    img = Label(startWindow, image=render, bd=0)

    img.image = render

    img.place(x=-100, y=-65)

    clickToPlay = Button(startWindow, text='Play!', width=8, font='Bizon 20 bold', bg='Black', fg='Yellow', relief=RIDGE, bd=0, command=lambda:runGame(startWindow))

    clickToPlay.place(x=75, y=125)

    authorName = Label(startWindow, text='Written by : Pamal Mangat', font='Times 6 bold', bg='Black', fg='Yellow')

    authorName.place(x=2, y=230)

    versionNum = Label(startWindow, text='[V 1.2]', font='Times 6 bold', bg='Black', fg='Red')

    versionNum.place(x=268, y=230)

    playMusic(r'C:UsersPamalDesktopDocumentsPython FolderPython ProjectsRock, Paper, ScissorsV 1.2Audio itle_Song.mp3')

    startWindow.maxsize(300, 250)

    startWindow.minsize(300, 250)

    startWindow.config(background='Black')

    startWindow.mainloop()

startScreen()