import tkinter

cat = [
[1, 0, 0, 0, 0, 0, 1, 2],
[0, 2, 0, 0, 0, 0, 3, 4],
[0, 0, 3, 0, 0, 0, 0, 0],
[0, 0, 0, 4, 0, 0, 0, 0],
[0, 0, 0, 0, 5, 0, 0, 0],
[0, 0, 0, 0, 0, 6, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 2, 3, 4, 0, 0]
]

def draw_cat():
    for y in range(10):
        for x in range(8):
            if cat[y][x] > 0:
                cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT')

def drop_cat():
    for y in range(8, -1, -1):
        for x in range(8):
            if cat[y][x] != 0 and cat[y+1][x] == 0:
                cat[y+1][x] = cat[y][x]
                cat[y][x] = 0

def game_main():
    drop_cat()
    cvs.delete('CAT')
    draw_cat()
    root.after(100, game_main)

root = tkinter.Tk()
root.title('讓貓咪落下')
root.resizable(False, False)
cvs = tkinter.Canvas(root, width = 912, height = 768)
cvs.pack()

bg = tkinter.PhotoImage(file = 'images/cat_bg.png')

img_cat = [
    None,
    tkinter.PhotoImage(file = 'images/cat1.png'),
    tkinter.PhotoImage(file = 'images/cat2.png'),
    tkinter.PhotoImage(file = 'images/cat3.png'),
    tkinter.PhotoImage(file = 'images/cat4.png'),
    tkinter.PhotoImage(file = 'images/cat5.png'),
    tkinter.PhotoImage(file = 'images/cat6.png'),
    tkinter.PhotoImage(file= 'images/cat_paw.png')
]

cvs.create_image(456, 384, image = bg)
game_main()
root.mainloop()