Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This week you learned how to draw basic geometric shapes with Python and TKInter. Use this knowledge to develop a simple slot machine game: show

This week you learned how to draw basic geometric shapes with Python and TKInter.

Use this knowledge to develop a simple slot machine game:

  • show 3 'slots' (squares) in a horizontal row
  • show a 'Play' button below the slots
  • when the user clicks the Play button, display a randomly-chosen shape in each slot, choosing from these - square, circle, triangle
  • Fill each shape with a color - it's ok to hard-code one color per shape
  • if all 3 slots show the same shape, display a 'Winner!' message below the Play button

image text in transcribed

Hint

  • Define a function for creating each shape type
  • Your functions should accept a parameter (or parameters) that identify where the shape should be drawn,
  • Rectangle objects have properties you can use to inform your drawing functions:
r = Rectangle(Point(10,10), Point(90,90)) print(r.p1,r.p2) # print upper_left & lower right print(r.getCenter()) # print center point of rectangle 
  • You can use this code to get started:
from graphics import * import random win = GraphWin("Slot Machine",600,600) # one-time definition of variables and functions can be here while True: p = win.getMouse() print("You clicked", p.getX(), p.getY()) # code that should execute with each mouse click should be here
 # this code generates a random number between 0 - 2 choice = random.randrange(3) 
  • Consider what Python data structures you can use to keep track of which shapes are displayed

Extra Credit:

  • Clear previously drawn shapes each time the 'Play' button is clicked,
  • add support for more shapes - e.g. oval, diamond, crescent moon, smiley face
  • add support for different color combinations - e.g. red square, blue square, etc.

Re-drawing Slots:

This assignment doesn't require you to clear shapes before drawing new ones. But the user experience is better if you do. How can you do that?

TKinter graphics objects all support an undraw() method, as in this example:

s = Circle(Point(100,100), 30) s.draw(win) # some other code s.undraw()

To use this approach, your program should keep track of generated shapes and undraw() them when re-starting the 'Play' step.

Rubric

HW 8 Rubric

Jackpot Spin

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

The Functions of Language Problems with Language

Answered: 1 week ago

Question

The Nature of Language

Answered: 1 week ago