Пример #1
0
def start_game():
    start_button.config(state=DISABLED)  # no accidental presses while play
    game = Gamelogic(34, 34)
    game.add_rand()
    graphic = Graphic(34, 34, game, root)
    graphic.init_graphic(320, 20)
    while True:
        graphic.root.after(50)
        graphic.game.update_field()
        graphic.game.found_piece()
        graphic.update_graphic()
        score_label.config(text="Score: " + str(graphic.game.score))
        score_label.place(x=20, y=460)
        graphic.root.update_idletasks()
        graphic.root.update()
        if graphic.game.is_lost() is True:
            break
    graphic.root.after(500, graphic.end())
    start_button.config(state="normal")
    if graphic.game.score > int(highscore):
        highscore_label.config(text="Highscore: " + str(graphic.game.score))
        highscore_label.place(x=20, y=500)
        with open("highscore.txt", "w") as f:
            f.write(str(graphic.game.score))
            f.close()