-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDartBoard.py
More file actions
64 lines (47 loc) · 2.13 KB
/
Copy pathDartBoard.py
File metadata and controls
64 lines (47 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from tkinter import *
from PIL import ImageTk, Image
# GUI
import time
class DartBoard():
shots = []
roundCurr = 0
def __init__(self, player, shots, maxRounds, maxShots):
self.player = player
self.shots = shots
self.maxRounds = maxRounds
self.maxShots = maxShots
def run(self):
self.top = Tk()
self.top.geometry("420x480")
self.top.title('Player ' + str(self.player))
#todo labelll
image = Image.open("DartBoard.png")
self.bg_image = ImageTk.PhotoImage(image)
self.canvas = Canvas(self.top, width=self.bg_image.width(), height=self.bg_image.height())
self.canvas.pack()
self.canvas.create_image(0, 0, image=self.bg_image, anchor="nw")
self.roundLabel = Label(self.top, text = "Runda: " + str(self.roundCurr))
self.roundLabel.pack()
def button_click():
self.roundCurr += 1
if(self.roundCurr > self.maxRounds):
self.top.destroy()
return
self.roundLabel.config(text = "Runda: " + str(self.roundCurr))
self.drawRound(self.roundCurr)
button = Button(self.top, text="Następna runda:", width = 210, height = 30, command = button_click)
button.pack()
self.top.mainloop()
def drawRound(self, round):
self.canvas.create_image(0, 0, image=self.bg_image, anchor="nw")
move = (round - 1) * self.maxShots
for i in range (0, self.maxShots):
self.takeShot(self.shots[ i + move ][0], self.shots[i + move ][1])
def takeShot(self, xCord, yCord):
circle_x = int((xCord * 210 / 5.0) + 210) # X-coordinate of the circle's center
circle_y = int((yCord * -210 / 5.0) + 210) # Y-coordinate of the circle's center
circle_radius = 5 # Radius of the circle
circle_color = "light blue" # Color of the circle
self.canvas.create_oval(circle_x - circle_radius, circle_y - circle_radius,
circle_x + circle_radius, circle_y + circle_radius,
fill=circle_color)