If the version of your code on github does not run, it is considered non-functioning. If it does not run on your personal computer WITHOUT CHANGES, it is considered non-functioning.
WARNING: Graders will not grade any part of your code that does not execute.
TOTAL: 20 points
In this lab, you will learn to:
The simulation will consist of randomly throwing a number of darts at a dartboard. The set up for our board is shown below.
Using the Pygame draw module, set up a dartboard on screen similar to the one pictured above. Have the dartboard cover the entire pygame window.
In order to determine the size of the circle and lines, we will need to get the screen size. Luckily, pygame has a module and function for this:
display.get_window_size: returns the width and length of the screen in a list
You can get screen width specifically by indexing into the returned list:
screen_size_variable[0]
screen_size_variable[1]
Take a closer look at the display.set_mode documentation to set the window size yourself.
You may use any background colors you like as long as the dartboard is distinguishable from the backboard. In other words, no orange dartboard and orange backboard
In a GUI program, the coordinate system works a bit different than what you may be used to:
Keep these GUI concepts in mind as you are sizing and placing your circle and lines.
Make sure your dartboard is appearing correctly before going on to part B.
Now that we have our dartboard setup, we can throw darts at it. You can assume that the players are good enough at throwing darts that they always hit the wood (inside the window). Sometimes the darts will hit the dartboard (circle) and sometimes they will miss.
We can use the random module’s randrange() function to generate the x and y coordinates of the dart.
Generate a random value between 0 and screen size for the x and y coordinate.
Once we determine the dart's landing coordinates, you can draw a dot (i.e. a circle with a very small radius) at that point location to mark it.
You can determine if the dart lands inside the circle using the following formula:
distance_from_center = math.hypot(x1-x2, y1-y2) #the distance formula
is_in_circle = distance_from_center <= width/2 #screen width
You should use one color for when the player misses and another for when they successfully hit the dartboard. Use any colors you want as long as they are visible.
Verify your code works by writing a loop that throws 10 random darts at the board.
ch03/
lab/
main.py
Complete your submission by making a commit and push using either the Source Control tab in VSCode or the command line in the shell.
Go to your repo on Github to verify your changes were pushed. If your changes are there, that's it! You've completed the work for this lab.