王婷儀甲班期末考PYTHON貪吃蛇增加速度

= GAME_WIDTH:
        return True
    elif y < 0 or y >= GAME_HEIGHT:
        return True
    for body_part in snake.coordinates[1:]:
        if x == body_part[0] and y == body_part[1]:
            return True
    return False
def game_over():
    #canvas.delete(ALL)
    canvas.create_text(canvas.winfo_width()/2, canvas.winfo_height()/2,
                       font=('consolas',40), text="王婷儀成功增加速度", fill="red", tag="gameover")
window = Tk()
window.title("王婷儀Snake game貪吃")
window.resizable(False, False)
score = 0
direction = 'down'
label = Label(window, text="王婷儀分數:{}".format(score), font=('consolas', 40))
label.pack()
canvas = Canvas(window, bg=BACKGROUND_COLOR, height=GAME_HEIGHT, width=GAME_WIDTH)
canvas.pack()
window.update()
window_width = window.winfo_width()
window_height = window.winfo_height()
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = int((screen_width/2) - (window_width/2))
y = int((screen_height/2) - (window_height/2))
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
window.bind('', lambda event: change_direction('left'))
window.bind('', lambda event: change_direction('right'))
window.bind('', lambda event: change_direction('up'))
window.bind('', lambda event: change_direction('down'))
snake = Snake()
food = Food()
next_turn(snake, food)
window.mainloop()# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

留言

  1. 期末考.https://wangtingyiprincess.blogspot.com/2026/01/python.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

王婷儀PYTHON條件判斷if否則elif

王python公主製作tkinter金融常識測驗

王婷儀python全域變數global和判斷if