Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a long, multi part homework assignment that I need help on. This is all using python with imported graphics.py The game begins by

I have a long, multi part homework assignment that I need help on.

This is all using python with imported graphics.py

  1. The game begins by allowing the player to place a certain number of red rocks, represented by Circle objects, around the window. Because we'll need to use the rocks later for collision detection, we should store them in a list. create function, generateRocks(n, win) -> rockList, that waits for the user to click n times, each time drawing a red circle at the clicked location and then adding it to the list. The function should return the list so that it can be used later.
  2. We also need to track the number of times each rock has been hit. Since the rocks are stored in a list, it makes sense that we track each rock's hit count in a parallel list. For example, if our game has 3 rocks, then we should also have a list of 3 numbers representing the hit counters. The rocks' hit counts should begin at 0. create function, buildHitList(n) -> hitList, that returns a list a list of n numbers representing the initial hit counts of the rocks.
  3. In order to determine whether two graphical objects have collided, it would be useful to have a function that calculates the distance between two points. create function, distance(point1, point2) -> dist, that returns the Euclidean (straight line) distance between two Point objects.
  4. Now, we can begin to implement collision detection. create function, didCollide(ball, rock) -> Boolean, that returns whether or not the ball overlaps with the specified rock. Both the ball and rock are represented by Circle objects. Make sure to use the existing distance() function from the previous problem instead of introducing duplicate code.
  5. create function, hitVertical(ball, win) -> Boolean, that returns whether or not the ball overlaps with a vertical wall, i.e. the left or right side of the window. You can use the GraphWin object to get the dimensions of the window.
  6. create function, hitHorizontal(ball, win) -> Boolean, that returns whether or not the ball overlaps with a horizontal wall, i.e. the top or bottom side of the window. You can use the GraphWin object to get the dimensions of the window.
  7. When the ball strikes a wall, it should change to a random color. create function, randomColor() -> colorString, that returns a string representing a random color. You have two functions at your disposal: color_rgb(r, g, b) (from the graphics library) returns a color string given three numbers representing its red, green, and blue components, respectively. See section 4.8.5 in the book (p. 121) for more details. randint(a, b) (from the random library) returns a random number between a and b, inclusive.

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions