So a kid in my class wanted more of a challenge...the professor gave us one...and I have no idea on this problem.

Here's the instructions:

Darts scorer. Write a program that draws a darts target and allows the user to click on the target to represent darts hitting the target. The program should output, in the window, a score for each click, and a running score for the entire game.


Landing a dart in the bull's eye is worth 50 points. A dart in the bull is worth 25 points. The outer ring is called the double ring. A dart in the double ring in the 20 section would be worth 40 points. A dart in the triple ring would be worth three times the score in that section. Darts in the areas between the rings and the bulls are worth the points on the outside of the target.

The player starts with 501 points, reducing the total by each score. The player must go out on an exact score, i.e. if the player has 10 points remaining, the player needs exactly 10 points to go out; throwing 12 will not work.

Here's the pic of what it's spose to look like-colors do not matter

Here are two Python code smaples using the Tkinter GUI. Each example has a hint how to do the dart game:

from Tkinter import *

root = Tk()
root.title("Archery Target")

canvas = Canvas(root, width=600, height=600)

# draw five circles, largest one first, circles draw within a 
# square with given upper left corner and lower right corner coordinates


This tells you if the mouse has been clicked on target:

from Tkinter import *
import random

def create_rect():
    chance = random.sample(range(1, 250), 4)
    print chance  # test  eg. [72, 206, 116, 166]
    canvas.create_rectangle(chance, fill="red")

def check_rect(event):
    rect = canvas.find_overlapping(event.x, event.y, event.x, event.y)
    if rect:
        # delete old rectangle
        # create new rectangle

root = Tk()
root.title("click on red")

canvas = Canvas(root, height=250, width=250, bg="yellow")

# create the starting random rectangle

# respond to left mouse button click
canvas.bind("<Button-1>", check_rect)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.