Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import randrange as rnd, choice
- import time
- root = Tk()
- root.geometry('800x600')
- root.title("Игра поймай шарик")
- canv = Canvas(root, bg='lightblue')
- canv.pack(fill=BOTH, expand=1)
- colors = ['lightyellow', 'lightgray', 'gray', 'pink', 'violet', 'brown', 'red', 'orange', 'yellow', 'green', 'cyan',
- 'blue', 'magenta', 'black', 'gray', 'lightgreen']
- x = 0
- y = 0
- r = 0
- points = 0
- miss = 0
- zero = 0
- shut = 0
- def new_ball():
- global x, y, r, zero, res, shut
- canv.delete(ALL)
- res = canv.create_text(300, 20, text="заработал " + str(points) + " очков"
- + '/' + "промазал " + str(miss) + " раз" + '/' +
- "проворонил " + str(zero) + " шаров", font='Arial 15')
- x = rnd(100, 700)
- y = rnd(100, 500)
- r = rnd(20, 50)
- target = canv.create_oval(x - r, y - r, x + r, y + r, fill=choice(colors), width=0)
- if shut < 20:
- root.after(rnd(500, 3000), new_ball)
- else:
- canv.delete(ALL)
- res = canv.create_text(350, 250, text="Вы сделали " + str(shut) + " попыток! Вы набрали: " +
- str(points) + "балла(ов)", font='Arial 20')
- zero += 1
- def click(event):
- global points, miss, zero, res, shut
- if abs(x - event.x) < r / 2 and abs(y - event.y) < r / 2:
- points += 2
- zero -= 1
- elif abs(x - event.x) < r and abs(y - event.y) < r:
- points += 1
- zero -= 1
- else:
- miss += 1
- canv.delete(ALL)
- res = canv.create_text(300, 20, text="заработал " + str(points) + " очков"
- + '/' + "промазал " + str(miss) + " раз" + '/' +
- "проворонил " + str(zero) + " шаров", font='Arial 15')
- shut += 1
- root.after(1000, new_ball)
- canv.bind('<Button-1>', click)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment