![]() ![]() If not 0 <= < cell_number or not 0 <= < cell_number:Īny other suggestions are always welcome. So, please help me to add game over image when snake collide with itself and also add key "P" to restart the game and key "ESC" to exit the game, as same that I have done to def check_fail(self): The goal of the game is to eat as many apples as possible without colliding into yourself. The player is represented as snake, which grows if it eats an apple. The game is an arcade game and it has very simple logic, which is why it is an ideal example to demonstrate how to build games with Pygame. ![]() If which_direction = 4: which_direction = 0 The trio of the snakes were so heavy they busted through the home’s ceiling. Pause_text = c.create_text(302, 250, font='Terminal 30 bold', text="Press space to resume", fill='white') Global s, ap, run, which_direction, score If (c.coords(s) directions>=600 or \Ĭ.coords(s) directions>=600 or \Ĭ.coords(s) directions', restart) Square = c.create_rectangle(x, y, x 30, y 30, fill='', outline='white')Ĭ.move(s,directions,directions) Space - pause/start/restart game it dependsĬ = Canvas(root,bg='black', width=604, height=604, highlightthickness=0)Ĭ.create_text(302, 250, font='Terminal 30 bold', text="Press space to start", fill='white')ĭirections = ,] from tkinter import from random import randrange root Tk () root.geometry ('604圆04 300 100') root.title ('Snake') c Canvas (root,bg'black', width604, height604, highlightthickness0) c.pack () c.createtext (302, 250, font'Terminal 30 bold', text'Press space to start', fill'white') s directions -30,0, 0,-30, 30,0. I know that I should use comments, I am sorry. And this is normal because when I close window then it still runs while-loop and update() tries to access window which is already closed. I created snake as my first program with GUI, I didn't learn OOP yet, I get this problem only when I close window with Turtle. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |