Advertisement
plarmi

Sticks

Dec 3rd, 2023 (edited)
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. # https://habr.com/ru/sandbox/149940/
  2.  
  3. import tkinter
  4. import random
  5.  
  6. STICKS = 20
  7.  
  8. def c1():
  9.     global STICKS
  10.     STICKS -= 1
  11.     label1.config(text="| " * STICKS)
  12.     if STICKS <= 0:
  13.         label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
  14.         return None
  15.     computer_turn()
  16.  
  17. def c2():
  18.     global STICKS
  19.     STICKS -= 2
  20.     label1.config(text="| " * STICKS)
  21.     if STICKS <= 0:
  22.         label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
  23.         return None
  24.     computer_turn()
  25.  
  26. def c3():
  27.     global STICKS
  28.     STICKS -= 3
  29.     label1.config(text="| " * STICKS)
  30.     if STICKS <= 0:
  31.         label1.config(text=" " * 3 + "Компьютер победил!", foreground="red")
  32.         return None
  33.     computer_turn()
  34.  
  35. def computer_turn():
  36.     global STICKS
  37.     choice = random.randint(1, 3)
  38.     STICKS -= choice
  39.     label1.config(text="| " * STICKS)
  40.     if STICKS <= 0:
  41.         label1.config(text=" " * 7 + "Игрок победил!", foreground="green")
  42.     print(f"Компьютер убрал {choice} палочек")
  43.  
  44.  
  45. window = tkinter.Tk()
  46.  
  47. window.geometry("550x200")
  48. window.title("Палочки")
  49. window.resizable(False, False)
  50. window.iconbitmap("stick.ico")
  51.  
  52. text1 = tkinter.Label(window, text="Сколько палочек будете брать?")
  53. text1.pack()
  54.  
  55. button1 = tkinter.Button(window, text="1", command=c1)
  56. button1.place(x=210, y=30)
  57.  
  58. button2 = tkinter.Button(window, text="2", command=c2)
  59. button2.place(x=265, y=30)
  60.  
  61. button3 = tkinter.Button(window, text="3", command=c3)
  62. button3.place(x=320, y=30)
  63.  
  64. label1 = tkinter.Label(window, text="| " * STICKS, font=("Arial Bold", 30))
  65. label1.place(x=50, y=70)
  66.  
  67. button4 = tkinter.Button(window, text="Ход компьютера", command=computer_turn)
  68. button4.place(x=220, y=150)
  69.  
  70. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement