![]() ![]() Run the following command to download and play Python Snake! Note that this will download a file called snake.py into your current working directory. ![]() ![]() If a prompt like > shows up, then Python is installed. Check if you have Python installed by typing the command python and pressing enter in your command prompt or terminal. Most computers running macOS should have Python pre-installed. Use the arrow keys to move: the left arrow key to move left, the right arrow key to move right, the up arrow key to move up, and the down arrow key to move down. Additional download information is below. The code is well commented, and only requires Python2 to be installed, however, it does use Tkinter, which should come pre-installed with Python2, but may not be for various reasons. In this version, it is possible to move through walls, although it is possible to change this by editing the if statements starting on line 100. You are the snake move using the arrow keys, and avoid eating your own tail. The snake is colored green, and the apple is red. The game is just like the original: a snake trying to eat an apple. 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. Global variables are almost always a bad idea.The classic snake game made in Python Tkinter. You should stop using global variables and instead pass whatever variables you need between your functions. I think you should start looking at OOP pretty soon, but before that a glaring issue is that your functions all rely entirely on "side-effects" they don't accept any arguments and they return nothing. Usually people would write for _ in range(3): here to show that we don't actually care about the index of the iterator. Where the x in your for loop has nothing to do with the square dimensions. You also shouldn't use the same variable for different things, like this: def create_s(): The Civil Defense Department successfully subdued and removed those two. Your function here: if (c.coords(s) directions>=600 or \Ĭ.coords(s) directions<=-30 or \Ĭ.coords(s) directions<=-30) and run: According to Sinar Harian, two pythons were found in the ceiling.Both snakes were around 16 feet long and weighed 70 pounds. You should also take care in how you set up lines, and sometimes more cases are worth it simply since they make it easier to follow what's happening. Use clear and obvious names the common saying is that you would read a piece of code way more often than it is written, and it thus needs to be easy to understand-you might be surprised how little even your own code will make sense to you only days after having written it. Without deducing from functionality, I have no idea what variables like s and ap, or what functions like create_s() and s_move() do. Sp = c.create_text(10, 585, font='TimesNewRoman 10', text=f'speed: ', fill='white', anchor=W) If which_direction = -1: which_direction = 3 If which_direction = 4: which_direction = 0 Stock footage Python snake crawls on green screen background 68079439 HD/4K Download videos from Depositphotos Millions of royalty-free videos for. 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)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |