{"id":427366,"date":"2024-07-25T21:45:21","date_gmt":"2024-07-25T21:45:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=427366"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=427366","title":{"rendered":"<span>Donkey.bas \u043d\u0430 Python \u0432 170 \u0441\u0442\u0440\u043e\u043a<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044f \u0434\u0430\u0432\u043d\u0435\u043d\u044c\u043a\u043e \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0438\u0433\u0440\u0443\u0448\u043a\u0443 \u0438 \u043e\u043f\u044b\u0442 \u0438\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0434\u0430\u0436\u0435 \u0431\u044b\u043b, \u043d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0435 \ud83d\ude41<\/p>\n<p>\u041d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u043d\u0430\u044f \u0438\u0434\u0435\u044f: \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u043c\u0435\u0439\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0430\u0440\u043e\u0439 \u0438\u0433\u0440\u0443\u0448\u043a\u0438 \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: <a href=\"https:\/\/docs.python.org\/3\/library\/tkinter.html\" rel=\"noopener noreferrer nofollow\">Tkinter<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/time.html\" rel=\"noopener noreferrer nofollow\">Time<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/random.html\" rel=\"noopener noreferrer nofollow\">Random<\/a> \u0438 <a href=\"https:\/\/docs.python.org\/3\/library\/winsound.html\" rel=\"noopener noreferrer nofollow\">Winsound<\/a>. <\/p>\n<p>\u0414\u0430-\u0434\u0430, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <a href=\"https:\/\/pypi.org\/project\/pygame\/\" rel=\"noopener noreferrer nofollow\">Pygame\u2019\u0430<\/a>. \u042f \u0435\u0449\u0451 \u0441\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432 \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a\u0438 \u043d\u0435 \u043b\u044e\u0431\u0438\u043b \u043b\u0451\u0433\u043a\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 \u041f\u0430\u0441\u043a\u0430\u043b\u0435 \ud83d\ude42<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0438\u0433\u0440\u0443\u0448\u043a\u0443 <a href=\"https:\/\/en.wikipedia.org\/wiki\/DONKEY.BAS\" rel=\"noopener noreferrer nofollow\">Donkey<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0434\u0430\u043b\u0451\u043a\u043e\u043c 1981 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/IBM_PC_DOS\" rel=\"noopener noreferrer nofollow\">IBM PC DOS<\/a> \u0441\u0430\u043c\u0438\u043c \u0411\u0438\u043b\u043b\u043e\u043c \u0413\u0435\u0439\u0442\u0441\u043e\u043c.<\/p>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a)<\/p>\n<h3>\u041a\u0430\u043a \u0432\u0441\u0451 \u043f\u0438\u0441\u0430\u043b\u043e\u0441\u044c?<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043e\u043a\u043d\u043e \u0434\u043b\u044f \u0438\u0433\u0440\u044b. \u0417\u0434\u0435\u0441\u044c \u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u0438\u043a\u043e\u043d\u043a\u0443 \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043a\u043d\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u043a\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u044d\u043a\u0440\u0430\u043d\u0430.<\/p>\n<p>\u042f \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044e \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u0441\u0440\u0435\u0434\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\">import tkinter as tk import time from random import randint import winsound  # Create the main application window window = tk.Tk()  # Setting the window icon window.iconbitmap('resources\\icon.ico')  # Setting the window title window.title('DonkeyPy 1.0')  # Get the width and height of the screen screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight()  # Set the width and height of the window window_width = 718 window_height = 418  # Calculate coordinates for placing the window in the centre of the screen x = (screen_width \/\/ 2) - (window_width \/\/ 2) y = (screen_height \/\/ 2) - (window_height \/\/ 2)  # Apply window size and position window.geometry(f'{window_width}x{window_height}+{x}+{y}') # Prohibit window resizing window.resizable(False, False)<\/code><\/pre>\n<p>\u042f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0444\u043e\u043d\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u043c\u0435\u0442\u043a\u0430\u043c\u0438. \u041d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0436\u0430\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0448\u0443 <strong><em>Esc<\/em><\/strong>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0441\u0447\u0451\u0442 \u0434\u043b\u044f \u043e\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0451\u043b \u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0438 \u0441 \u043c\u0430\u0448\u0438\u043d\u043e\u0439:<\/p>\n<pre><code class=\"python\"># Set the background of the window window.image = tk.PhotoImage(file='resources\\zf.png') bg = tk.Label(window, image=window.image) bg.grid(row=0, column=0) bg.config(bg='#555555')  # Escape key label esc_lbl = tk.Label(window, text='Press Esc to exit', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) esc_lbl.place(x=500, y=345)  # Window closing function def exit(event):     if event.keysym == 'Escape':         window.destroy()  window.bind('&lt;KeyPress-Escape&gt;', exit)  # Donkey labels donkey_lbl = tk.Label(window, text='Donkey', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_lbl.place(x=26, y=40)  donkey_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_count.place(x=26, y=90)  donkey_loses = tk.Label(window, text='Donkey loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_loses.place(x=1000, y=1000)  # Donkey scoring function def donkey_points_count():     donkey_count['text'] = int(donkey_count['text']) + 1  donkey_wins = tk.PhotoImage(file='resources\\donkey_wins.png') donkey_wins_label = tk.Label(window) donkey_wins_label.image = donkey_wins donkey_wins_label['image'] = donkey_wins_label.image donkey_wins_label.place(x=1000, y=1000) donkey_wins_label.config(bg='#555555')  # Car labels car_lbl = tk.Label(window, text='Driver', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_lbl.place(x=500, y=40)  car_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_count.place(x=500, y=90)  driver_loses = tk.Label(window, text='Driver loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) driver_loses.place(x=1000, y=1000)  # Driver scoring function def driver_points_count():     car_count['text'] = int(car_count['text']) + 1  driver_wins = tk.PhotoImage(file='resources\\driver_wins.png') driver_wins_label = tk.Label(window) driver_wins_label.image = driver_wins driver_wins_label['image'] = driver_wins_label.image driver_wins_label.place(x=1000, y=1000) driver_wins_label.config(bg='#555555')<\/code><\/pre>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0435\u0433\u043e \u043d\u0430 \u043e\u043a\u043d\u043e. \u0417\u0430\u0442\u0435\u043c \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442 \u043c\u0430\u0448\u0438\u043d\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u043b\u0430\u0432\u0438\u0448 <strong><em>Right<\/em><\/strong> \u0438 <strong><em>Left<\/em><\/strong>, \u0438 \u0437\u0430\u0434\u0430\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\"># Uploading car image car = tk.PhotoImage(file='resources\\car.png') car_label = tk.Label(window) car_label.image = car car_label['image'] = car_label.image car_y = 280 car_label.place(x=250, y=car_y) car_label.config(bg='#555555')  car_y_initial = 280  # Car move function def move_car(event):     if car_y == 100:         return     else:         if event.keysym == 'Right':             car_label.place(x=380)         elif event.keysym == 'Left':             car_label.place(x=250)         winsound.PlaySound('sounds\\move_car.wav', 1)  window.bind('&lt;KeyPress-Right&gt;', move_car) window.bind('&lt;KeyPress-Left&gt;', move_car)  # Game restart function def restart_game():     global car_y, car_y_initial      car_y = car_y_initial      car_label.place(x=250)      donkey_loses.place(x=1000, y=1000)      driver_wins_label.place(x=1000, y=1000)      if car_count['text'] == 10:         car_count['text'] = int(car_count['text']) * 0         donkey_count['text'] = int(donkey_count['text']) * 0      change_road()<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u043b\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Tkinter, \u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e \u0435\u0433\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0435\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b (\u0438\u0445 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e 3 \u0448\u0442\u0443\u043a\u0438) \u0438 \u0441\u043a\u0440\u044b\u0442\u0438\u044f \u043c\u0435\u0442\u043a\u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"python\"># Uploading donkey image donkey = tk.PhotoImage(file='resources\\donkey.png') donkey_label = tk.Label(window) donkey_label.image = donkey donkey_label['image'] = donkey_label.image donkey_x = 365 donkey_y = -40 donkey_label.place(x=donkey_x, y=donkey_y) donkey_label.config(bg='#555555')  donkey_y_initial = -1340  # Game restart function in case of a donkey win def restart_game_2():     global car_y, car_y_initial, donkey_y, donkey_y_initial      car_y = car_y_initial     car_label.place(x=250, y=car_y)      donkey_y = donkey_y_initial  # Label hiding function def driver_loses_f():     driver_loses.place(x=1000, y=1000)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438: \u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u0438 \u043e\u0441\u043b\u043e\u043c.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b winfo_rootx() \u0438 winfo_rooty(), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u0417\u0430\u0442\u0435\u043c \u043e\u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043b\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\"># Function for checking image collision def check_collision():     car_x = car_label.winfo_rootx()     car_y = car_label.winfo_rooty()      donkey_x = donkey_label.winfo_rootx()     donkey_y = donkey_label.winfo_rooty()      # Condition, if the donkey wins     if car_x &gt;= donkey_x and car_x &lt;= donkey_x + donkey.width() and \\             car_y &gt;= donkey_y and car_y &lt;= donkey_y + donkey.height():         donkey_points_count()          winsound.PlaySound('sounds\\image_collision.wav', 1)          if donkey_count['text'] &lt; 10:             driver_loses.place(x=26, y=140)              restart_game_2()              window.after(2500, driver_loses_f)         else:             donkey_wins_label.place(x=498, y=225)              restart_game_3()              window.after(2500, donkey_wins_f)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043e\u0441\u043b\u0430 \u0432 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0438 \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u0444\u043b\u0430\u0433 is_moving \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True. \u0417\u0430\u0442\u0435\u043c \u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 <strong>Y<\/strong> \u043e\u0441\u043b\u0430 \u043d\u0430 50 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0435\u0433\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u0441 \u043c\u0430\u0448\u0438\u043d\u043e\u0439:<\/p>\n<pre><code class=\"python\">is_moving = False  # Donkey move function def move_donkey():     global is_moving, donkey_y, car_y      # If the function is already in progress, exit     if is_moving:         return      # Set the flag that the function is running     is_moving = True      donkey_y += 50     donkey_label.place(y=donkey_y)      # Checking for collision     window.after(1000, check_collision)      # Condition, if the donkey reaches a certain y-coordinate     if donkey_y == 360:         donkey_x = 365 if randint(1, 2) == 1 else 230          donkey_y = -40         donkey_label.place(x=donkey_x, y=donkey_y)          car_y -= 20         car_label.place(y=car_y)          # Condition, if the driver wins         if car_y == 100:             driver_points_count()              donkey_x = 1000             donkey_label.place(x=donkey_x)              if car_count['text'] &lt; 10:                 donkey_loses.place(x=500, y=140)                  window.after(2500, move_donkey)                 window.after(2500, restart_game)             else:                 driver_wins_label.place(x=498, y=225)                  window.after(2500, move_donkey)                 window.after(2500, restart_game)         else:                 window.after(110, move_donkey)      else:         window.after(110, move_donkey)      # Reset flag on function termination     is_moving = False<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u0434\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0434\u043e\u0440\u043e\u0433\u0443:<\/p>\n<pre><code class=\"python\"># Create one Label for the road road_label = tk.Label(window)  road_label.place(x=308, y=5)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043e\u0440\u043e\u0436\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043a\u0438 road_label, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u0436\u0434\u044b\u0435 10 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434:<\/p>\n<pre><code class=\"python\"># The function responsible for animating road markings def change_road():     if car_y == 100:         return     else:         current_time = (int(time.time() * 20) % 3) + 1         road = tk.PhotoImage(file='resources\\doroga_{}.png'.format(current_time))         road_label.image = road         road_label['image'] = road_label.image         road_label.config(bg='#555555')         window.after(10, change_road)<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">import tkinter as tk import time from random import randint import winsound window = tk.Tk() window.iconbitmap('resources\\icon.ico') window.title('DonkeyPy 1.0') screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() window_width = 718 window_height = 418 x = (screen_width \/\/ 2) - (window_width \/\/ 2) y = (screen_height \/\/ 2) - (window_height \/\/ 2) window.geometry(f'{window_width}x{window_height}+{x}+{y}') window.resizable(False, False) window.image = tk.PhotoImage(file='resources\\zf.png') bg = tk.Label(window, image=window.image) bg.grid(row=0, column=0) bg.config(bg='#555555') esc_lbl = tk.Label(window, text='Press Esc to exit', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) esc_lbl.place(x=500, y=345) def exit(event):     if event.keysym == 'Escape':         window.destroy() window.bind('&lt;KeyPress-Escape&gt;', exit) donkey_lbl = tk.Label(window, text='Donkey', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_lbl.place(x=26, y=40) donkey_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_count.place(x=26, y=90) donkey_loses = tk.Label(window, text='Donkey loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_loses.place(x=1000, y=1000) def donkey_points_count():     donkey_count['text'] = int(donkey_count['text']) + 1 donkey_wins = tk.PhotoImage(file='resources\\donkey_wins.png') donkey_wins_label = tk.Label(window) donkey_wins_label.image = donkey_wins donkey_wins_label['image'] = donkey_wins_label.image donkey_wins_label.place(x=1000, y=1000) donkey_wins_label.config(bg='#555555') car_lbl = tk.Label(window, text='Driver', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_lbl.place(x=500, y=40) car_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_count.place(x=500, y=90) driver_loses = tk.Label(window, text='Driver loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) driver_loses.place(x=1000, y=1000) def driver_points_count():     car_count['text'] = int(car_count['text']) + 1 driver_wins = tk.PhotoImage(file='resources\\driver_wins.png') driver_wins_label = tk.Label(window) driver_wins_label.image = driver_wins driver_wins_label['image'] = driver_wins_label.image driver_wins_label.place(x=1000, y=1000) driver_wins_label.config(bg='#555555') car = tk.PhotoImage(file='resources\\car.png') car_label = tk.Label(window) car_label.image = car car_label['image'] = car_label.image car_y = 280 car_label.place(x=250, y=car_y) car_label.config(bg='#555555') car_y_initial = 280 def move_car(event):     if car_y == 100:         return     else:         if event.keysym == 'Right':             car_label.place(x=380)         elif event.keysym == 'Left':             car_label.place(x=250)         winsound.PlaySound('sounds\\move_car.wav', 1) window.bind('&lt;KeyPress-Right&gt;', move_car) window.bind('&lt;KeyPress-Left&gt;', move_car) def restart_game():     global car_y, car_y_initial     car_y = car_y_initial     car_label.place(x=250)     donkey_loses.place(x=1000, y=1000)     driver_wins_label.place(x=1000, y=1000)     if car_count['text'] == 10:         car_count['text'] = int(car_count['text']) * 0         donkey_count['text'] = int(donkey_count['text']) * 0     change_road() donkey = tk.PhotoImage(file='resources\\donkey.png') donkey_label = tk.Label(window) donkey_label.image = donkey donkey_label['image'] = donkey_label.image donkey_x = 365 donkey_y = -40 donkey_label.place(x=donkey_x, y=donkey_y) donkey_label.config(bg='#555555') donkey_y_initial = -1340 def restart_game_2():     global car_y, car_y_initial, donkey_y, donkey_y_initial     car_y = car_y_initial     car_label.place(x=250, y=car_y)     donkey_y = donkey_y_initial def driver_loses_f():     driver_loses.place(x=1000, y=1000) def restart_game_3():     global car_y, car_y_initial, donkey_y, donkey_y_initial     car_y = car_y_initial     car_label.place(x=250, y=car_y)     donkey_y = donkey_y_initial     if donkey_count['text'] == 10:         donkey_count['text'] = int(donkey_count['text']) * 0         car_count['text'] = int(car_count['text']) * 0 def donkey_wins_f():     donkey_wins_label.place(x=1000, y=1000) def check_collision():     car_x = car_label.winfo_rootx()     car_y = car_label.winfo_rooty()     donkey_x = donkey_label.winfo_rootx()     donkey_y = donkey_label.winfo_rooty()     if car_x &gt;= donkey_x and car_x &lt;= donkey_x + donkey.width() and \\             car_y &gt;= donkey_y and car_y &lt;= donkey_y + donkey.height():         donkey_points_count()         winsound.PlaySound('sounds\\image_collision.wav', 1)         if donkey_count['text'] &lt; 10:             driver_loses.place(x=26, y=140)             restart_game_2()             window.after(2500, driver_loses_f)         else:             donkey_wins_label.place(x=498, y=225)             restart_game_3()             window.after(2500, donkey_wins_f) is_moving = False def move_donkey():     global is_moving, donkey_y, car_y     if is_moving:         return     is_moving = True     donkey_y += 50     donkey_label.place(y=donkey_y)     window.after(1000, check_collision)     if donkey_y == 360:         donkey_x = 365 if randint(1, 2) == 1 else 230         donkey_y = -40         donkey_label.place(x=donkey_x, y=donkey_y)         car_y -= 20         car_label.place(y=car_y)         if car_y == 100:             driver_points_count()             donkey_x = 1000             donkey_label.place(x=donkey_x)             if car_count['text'] &lt; 10:                 donkey_loses.place(x=500, y=140)                 window.after(2500, move_donkey)                 window.after(2500, restart_game)             else:                 driver_wins_label.place(x=498, y=225)                 window.after(2500, move_donkey)                 window.after(2500, restart_game)         else:                 window.after(110, move_donkey)     else:         window.after(110, move_donkey)     is_moving = False road_label = tk.Label(window) road_label.place(x=308, y=5) def change_road():     if car_y == 100:         return     else:         current_time = (int(time.time() * 20) % 3) + 1         road = tk.PhotoImage(file='resources\\doroga_{}.png'.format(current_time))         road_label.image = road         road_label['image'] = road_label.image         road_label.config(bg='#555555')         window.after(10, change_road) move_donkey() change_road() window.mainloop()<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f 172 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0439 \u0438\u0433\u0440\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/72c\/600\/229\/72c600229fdc517fee820500eb5cd629.png\" alt=\"DonkeyPy 1.0\" title=\"DonkeyPy 1.0\" width=\"718\" height=\"418\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/72c\/600\/229\/72c600229fdc517fee820500eb5cd629.png\"\/><\/p>\n<div><figcaption>DonkeyPy 1.0<\/figcaption><\/div>\n<\/figure>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u044f \u043f\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Android \u0432\u0435\u0440\u0441\u0438\u0438 \u0438\u0433\u0440\u044b (\u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0440\u0443\u043a\u0438 \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0439\u0434\u0443\u0442).<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0443 \u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0434\u0443\u043c\u0430\u044e, \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e. \u041f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0433\u0440\u044b \u0438\u043b\u0438 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e\u00a0<a href=\"https:\/\/github.com\/YuraFX\/DonkeyPy\" rel=\"noopener noreferrer nofollow\">\u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430 GitHub<\/a>.<\/p>\n<p>\u0421 \u0432\u0430\u043c\u0438 \u0431\u044b\u043b Yura_FX. \u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043c\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \ud83d\ude42<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/831198\/\"> https:\/\/habr.com\/ru\/articles\/831198\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044f \u0434\u0430\u0432\u043d\u0435\u043d\u044c\u043a\u043e \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0438\u0433\u0440\u0443\u0448\u043a\u0443 \u0438 \u043e\u043f\u044b\u0442 \u0438\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0434\u0430\u0436\u0435 \u0431\u044b\u043b, \u043d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0435 \ud83d\ude41<\/p>\n<p>\u041d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u043d\u0430\u044f \u0438\u0434\u0435\u044f: \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u043c\u0435\u0439\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0430\u0440\u043e\u0439 \u0438\u0433\u0440\u0443\u0448\u043a\u0438 \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: <a href=\"https:\/\/docs.python.org\/3\/library\/tkinter.html\" rel=\"noopener noreferrer nofollow\">Tkinter<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/time.html\" rel=\"noopener noreferrer nofollow\">Time<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/random.html\" rel=\"noopener noreferrer nofollow\">Random<\/a> \u0438 <a href=\"https:\/\/docs.python.org\/3\/library\/winsound.html\" rel=\"noopener noreferrer nofollow\">Winsound<\/a>. <\/p>\n<p>\u0414\u0430-\u0434\u0430, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <a href=\"https:\/\/pypi.org\/project\/pygame\/\" rel=\"noopener noreferrer nofollow\">Pygame\u2019\u0430<\/a>. \u042f \u0435\u0449\u0451 \u0441\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432 \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a\u0438 \u043d\u0435 \u043b\u044e\u0431\u0438\u043b \u043b\u0451\u0433\u043a\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 \u041f\u0430\u0441\u043a\u0430\u043b\u0435 \ud83d\ude42<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0438\u0433\u0440\u0443\u0448\u043a\u0443 <a href=\"https:\/\/en.wikipedia.org\/wiki\/DONKEY.BAS\" rel=\"noopener noreferrer nofollow\">Donkey<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0434\u0430\u043b\u0451\u043a\u043e\u043c 1981 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/IBM_PC_DOS\" rel=\"noopener noreferrer nofollow\">IBM PC DOS<\/a> \u0441\u0430\u043c\u0438\u043c \u0411\u0438\u043b\u043b\u043e\u043c \u0413\u0435\u0439\u0442\u0441\u043e\u043c.<\/p>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a)<\/p>\n<h3>\u041a\u0430\u043a \u0432\u0441\u0451 \u043f\u0438\u0441\u0430\u043b\u043e\u0441\u044c?<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043e\u043a\u043d\u043e \u0434\u043b\u044f \u0438\u0433\u0440\u044b. \u0417\u0434\u0435\u0441\u044c \u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u0438\u043a\u043e\u043d\u043a\u0443 \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043a\u043d\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u043a\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u044d\u043a\u0440\u0430\u043d\u0430.<\/p>\n<p>\u042f \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044e \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u0441\u0440\u0435\u0434\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\">import tkinter as tk import time from random import randint import winsound  # Create the main application window window = tk.Tk()  # Setting the window icon window.iconbitmap('resources\\icon.ico')  # Setting the window title window.title('DonkeyPy 1.0')  # Get the width and height of the screen screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight()  # Set the width and height of the window window_width = 718 window_height = 418  # Calculate coordinates for placing the window in the centre of the screen x = (screen_width \/\/ 2) - (window_width \/\/ 2) y = (screen_height \/\/ 2) - (window_height \/\/ 2)  # Apply window size and position window.geometry(f'{window_width}x{window_height}+{x}+{y}') # Prohibit window resizing window.resizable(False, False)<\/code><\/pre>\n<p>\u042f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0444\u043e\u043d\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u043c\u0435\u0442\u043a\u0430\u043c\u0438. \u041d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0436\u0430\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0448\u0443 <strong><em>Esc<\/em><\/strong>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0441\u0447\u0451\u0442 \u0434\u043b\u044f \u043e\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0451\u043b \u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0438 \u0441 \u043c\u0430\u0448\u0438\u043d\u043e\u0439:<\/p>\n<pre><code class=\"python\"># Set the background of the window window.image = tk.PhotoImage(file='resources\\zf.png') bg = tk.Label(window, image=window.image) bg.grid(row=0, column=0) bg.config(bg='#555555')  # Escape key label esc_lbl = tk.Label(window, text='Press Esc to exit', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) esc_lbl.place(x=500, y=345)  # Window closing function def exit(event):     if event.keysym == 'Escape':         window.destroy()  window.bind('&lt;KeyPress-Escape&gt;', exit)  # Donkey labels donkey_lbl = tk.Label(window, text='Donkey', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_lbl.place(x=26, y=40)  donkey_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_count.place(x=26, y=90)  donkey_loses = tk.Label(window, text='Donkey loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) donkey_loses.place(x=1000, y=1000)  # Donkey scoring function def donkey_points_count():     donkey_count['text'] = int(donkey_count['text']) + 1  donkey_wins = tk.PhotoImage(file='resources\\donkey_wins.png') donkey_wins_label = tk.Label(window) donkey_wins_label.image = donkey_wins donkey_wins_label['image'] = donkey_wins_label.image donkey_wins_label.place(x=1000, y=1000) donkey_wins_label.config(bg='#555555')  # Car labels car_lbl = tk.Label(window, text='Driver', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_lbl.place(x=500, y=40)  car_count = tk.Label(window, text=0, bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) car_count.place(x=500, y=90)  driver_loses = tk.Label(window, text='Driver loses!', bg='#555555', fg='#C0C0C0', font=('Comic Sans MS', 16, 'bold')) driver_loses.place(x=1000, y=1000)  # Driver scoring function def driver_points_count():     car_count['text'] = int(car_count['text']) + 1  driver_wins = tk.PhotoImage(file='resources\\driver_wins.png') driver_wins_label = tk.Label(window) driver_wins_label.image = driver_wins driver_wins_label['image'] = driver_wins_label.image driver_wins_label.place(x=1000, y=1000) driver_wins_label.config(bg='#555555')<\/code><\/pre>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0435\u0433\u043e \u043d\u0430 \u043e\u043a\u043d\u043e. \u0417\u0430\u0442\u0435\u043c \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442 \u043c\u0430\u0448\u0438\u043d\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u043b\u0430\u0432\u0438\u0448 <strong><em>Right<\/em><\/strong> \u0438 <strong><em>Left<\/em><\/strong>, \u0438 \u0437\u0430\u0434\u0430\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\"># Uploading car image car = tk.PhotoImage(file='resources\\car.png') car_label = tk.Label(window) car_label.image = car car_label['image'] = car_label.image car_y = 280 car_label.place(x=250, y=car_y) car_label.config(bg='#555555')  car_y_initial = 280  # Car move function def move_car(event):     if car_y == 100:         return     else:         if event.keysym == 'Right':             car_label.place(x=380)         elif event.keysym == 'Left':             car_label.place(x=250)         winsound.PlaySound('sounds\\move_car.wav', 1)  window.bind('&lt;KeyPress-Right&gt;', move_car) window.bind('&lt;KeyPress-Left&gt;', move_car)  # Game restart function def restart_game():     global car_y, car_y_initial      car_y = car_y_initial      car_label.place(x=250)      donkey_loses.place(x=1000, y=1000)      driver_wins_label.place(x=1000, y=1000)      if car_count['text'] == 10:         car_count['text'] = int(car_count['text']) * 0         donkey_count['text'] = int(donkey_count['text']) * 0      change_road()<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u043b\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Tkinter, \u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e \u0435\u0433\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0435\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b (\u0438\u0445 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e 3 \u0448\u0442\u0443\u043a\u0438) \u0438 \u0441\u043a\u0440\u044b\u0442\u0438\u044f \u043c\u0435\u0442\u043a\u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430 \u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"python\"># Uploading donkey image donkey = tk.PhotoImage(file='resources\\donkey.png') donkey_label = tk.Label(window) donkey_label.image = donkey donkey_label['image'] = donkey_label.image donkey_x = 365 donkey_y = -40 donkey_label.place(x=donkey_x, y=donkey_y) donkey_label.config(bg='#555555')  donkey_y_initial = -1340  # Game restart function in case of a donkey win def restart_game_2():     global car_y, car_y_initial, donkey_y, donkey_y_initial      car_y = car_y_initial     car_label.place(x=250, y=car_y)      donkey_y = donkey_y_initial  # Label hiding function def driver_loses_f():     driver_loses.place(x=1000, y=1000)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438: \u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u0438 \u043e\u0441\u043b\u043e\u043c.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b winfo_rootx() \u0438 winfo_rooty(), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u0417\u0430\u0442\u0435\u043c \u043e\u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043b\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\"># Function for checking image collision def check_collision():     car_x = car_label.winfo_rootx()     car_y = car_label.winfo_rooty()      donkey_x = donkey_label.winfo_rootx()     donkey_y = donkey_label.winfo_rooty()      # Condition, if the donkey wins     if car_x &gt;= donkey_x and car_x &lt;= donkey_x + donkey.width() and \\             car_y &gt;= donkey_y and car_y &lt;= donkey_y + donkey.height():         donkey_points_count()          winsound.PlaySound('sounds\\image_collision.wav', 1)          if donkey_count['text'] &lt; 10:             driver_loses.place(x=26, y=140)              restart_game_2()              window.after(2500, driver_loses_f)         else:             donkey_wins_label.place(x=498, y=225)              restart_game_3()              window.after(2500, donkey_wins_f)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043e\u0441\u043b\u0430 \u0432 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e, \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0438 \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e \u0444\u043b\u0430\u0433 is_moving \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True. \u0417\u0430\u0442\u0435\u043c \u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 <strong>Y<\/strong> \u043e\u0441\u043b\u0430 \u043d\u0430 50 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0435\u0433\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u0441 \u043c\u0430\u0448\u0438\u043d\u043e\u0439:<\/p>\n<pre><code class=\"python\">is_moving = False  # Donkey move function def move_donkey():     global is_moving, donkey_y, car_y      # If the function is already in progress, exit     if is_moving:         return      # Set the flag that the function is running     is_moving = True      donkey_y += 50     donkey_label.place(y=donkey_y)      # Checking for collision     window.after(1000, check_collision)      # Condition, if the donkey reaches a certain y-coordinate     if donkey_y == 360:         donkey_x = 365 if randint(1, 2) == 1 else 230          donkey_y = -40         donkey_label.place(x=donkey_x, y=donkey_y)          car_y -= 20         car_label.place(y=car_y)          # Condition, if the driver wins         if car_y == 100:             driver_points_count()              donkey_x = 1000             donkey_label.place(x=donkey_x)              if car_count['text'] &lt; 10:                 donkey_loses.place(x=500, y=140)                  window.after(2500, move_donkey)                 window.after(2500, restart_game)             else:                 driver_wins_label.place(x=498, y=225)                  window.after(2500, move_donkey)                 window.after(2500, restart_game)         else:                 window.after(110, move_donkey)      else:         window.after(110, move_donkey)      # Reset flag on function termination     is_moving = False<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u0434\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0434\u043e\u0440\u043e\u0433\u0443:<\/p>\n<pre><code class=\"python\"># Create one Label for the road road_label = tk.Label(window)  road_label.place(x=308, y=5)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043e\u0440\u043e\u0436\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043a\u0438 road_label, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u0436\u0434\u044b\u0435 10 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434:<\/p>\n<pre><code class=\"python\"># The function responsible for animating road markings def change_road():     if car_y == 100:         return     else:         current_time = (int(time.time() * 20) % 3) + 1         road = tk.PhotoImage(file='resources\\doroga_{}.png'.format(current_time))         road_label.image = road         road_label['image'] = road_label.image         road_label.config(bg='#555555')         window.after(10, change_road)<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">import tkinter as tk import time from random import randint import winsound window = tk.Tk() window.iconbitmap('resources\\icon.ico') window.title('DonkeyPy 1.0') screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() window_width = 718 window_height = 418 x = (screen_width \/\/ 2) - (window_width \/\/ 2) y =<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-427366","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427366"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427366\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}