0
0 комментариев

[apcode language=»python»]

from tkinter import *
 bomb = 100
score = 0
press_return = True
  def start(event):
    global press_return
    global bomb
    global score
    if not press_return:
        pass
    else:
        bomb = 100
        score = 0
        label.config(text='')
        update_bomb()
        update_score()
        update_display()
        press_return = False
  def update_display():
    global bomb
    global score
    if bomb > 50:
        bomb_label.config(image=normal_photo)
    elif 0 < bomb <= 50:
        bomb_label.config(image=no_photo)
    else:
        bomb_label.config(image=bang_photo)
    fuse_label.config(text='Fuse: ' + str(bomb))
    score_label.config(text='Score: ' + str(score))
    fuse_label.after(100, update_display)
  def update_bomb():
    global bomb
    bomb -= 5
    if is_alive():
        fuse_label.after(400, update_bomb)
  def update_score():
    global score
    score += 1
    if is_alive():
        score_label.after(3000, update_score)
    else:
        score -=1
 def click():
    global bomb
    if is_alive():
        bomb += 0
   def is_alive():
    global bomb
    global press_return
    if bomb <= 0:
        bomb=0
        label.config(text='Bang! Bang! Bang!')
        press_return = True
        return False
    else:
        return True
  root = Tk()
root.title('Bang Bang')
root.geometry('500x650')
 label = Label(root, text='Press [enter] to start the game', font=('Comic Sans MS', 12), fg='#FF8C00')
label.pack()
 fuse_label = Label(root, text='Fuse: ' + str(bomb), font=('Comic Sans MS', 14), fg='#FF8C00')
fuse_label.pack()
 score_label = Label(root, text='Score: ' + str(score), font=('Comic Sans MS', 14), fg='#FF8C00')
score_label.pack()
 no_photo = PhotoImage(file='img/2.gif')
normal_photo = PhotoImage(file='img/1.gif')
bang_photo = PhotoImage(file='img/3.gif')
 bomb_label = Label(root, image=normal_photo)
bomb_label.pack()
 click_button = Button(root, text='Click me', bg='#000000', fg='#FF8C00', width=15,
                      font=('Comic Sans MS', 14), command=click)
click_button.pack()
 root.bind('<Return>', start)
 root.mainloop()

[/apcode]

Решенный вопрос
Добавить комментарий