<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[The snake game in python]]></title><description><![CDATA[<p dir="auto">Hi: D</p>
<p dir="auto">My native language is not Spanish and I am using the translator, sorry if you found spelling problems</p>
<p dir="auto">Well, in this publication I will share the code of the snake game, first of all, credits to the channel “Python World”, or, in English “Python World”</p>
<p dir="auto">here is the code:</p>
<p dir="auto">import turtle<br />
import time<br />
import random</p>
<p dir="auto">posponer = 0.1</p>
<p dir="auto">score = 0<br />
high_score = 0</p>
<p dir="auto">wn = turtle.Screen()<br />
wn.title(“Snake”)<br />
wn.bgcolor(“light green”)<br />
wn.setup(width = 600, height = 600)<br />
wn.tracer(0)</p>
<p dir="auto">cabeza = turtle.Turtle()<br />
cabeza.speed(0)<br />
cabeza.shape(“square”)<br />
cabeza.color(“green”)<br />
cabeza.penup()<br />
cabeza.goto(0,0)<br />
cabeza.direction = “stop”</p>
<p dir="auto">comida = turtle.Turtle()<br />
comida.speed(0)<br />
comida.shape(“circle”)<br />
comida.color(“red”)<br />
comida.penup()<br />
comida.goto(0,100)</p>
<p dir="auto">segmentos = []</p>
<p dir="auto">texto = turtle.Turtle()<br />
texto.speed(0)<br />
texto.color(“white”)<br />
texto.penup()<br />
texto.hideturtle()<br />
texto.goto(0,220)<br />
texto.write(“Score: 0       High Score: 0”, align = “center”, font =(“Arial Black”, 24, “normal”))</p>
<p dir="auto">def arriba():<br />
cabeza.direction = “up”<br />
def abajo():<br />
cabeza.direction = “down”<br />
def izquierda():<br />
cabeza.direction = “left”<br />
def derecha():<br />
cabeza.direction = “right”</p>
<p dir="auto">def mov():<br />
if cabeza.direction == “up”:<br />
y = cabeza.ycor()<br />
cabeza.sety(y + 20)</p>
<pre><code>if cabeza.direction == "down":
    y = cabeza.ycor()
    cabeza.sety(y - 20)
    
if cabeza.direction == "left":
    x = cabeza.xcor()
    cabeza.setx(x - 20)
    
if cabeza.direction == "right":
    x = cabeza.xcor()
    cabeza.setx(x + 20)
</code></pre>
<p dir="auto">wn.listen()<br />
wn.onkeypress(arriba, “Up”)<br />
wn.onkeypress(abajo, “Down”)<br />
wn.onkeypress(izquierda, “Left”)<br />
wn.onkeypress(derecha, “Right”)</p>
<p dir="auto">while True:<br />
wn.update()</p>
<pre><code>if cabeza.xcor() &gt; 280 or cabeza.xcor() &lt; -290 or cabeza.ycor() &gt; 280 or cabeza.ycor() &lt; -280:
    time.sleep(1)
    cabeza.goto(0,0)
    cabeza.direction = "stop"
    
    for segmento in segmentos:
        segmento.goto(1000,1000)
        
    segmentos.clear()
    
    score = 0
    texto.clear()
    texto.write("Score: {}      High Score: {}".format(score, high_score), 
            align = "center", font =("Arial Black", 24, "normal"))
    

if cabeza.distance(comida) &lt; 20:
    x = random.randint(-280,280)
    y = random.randint(-280,280)
    comida.goto(x,y)
    
    cuerpo = turtle.Turtle()
    cuerpo.speed(0)
    cuerpo.shape("square")
    cuerpo.color("green")
    cuerpo.penup()
    segmentos.append(cuerpo)
    
    score += 10
    
    if score &gt; high_score:
        high_score = score
        
    texto.clear()
    texto.write("Score: {}     High Score: {}".format(score, high_score), 
            align = "center", font =("Arial Black", 24, "normal"))
    
totalSeg = len(segmentos)
for index in range(totalSeg -1, 0, -1):
    x = segmentos[index - 1].xcor()
    y = segmentos[index - 1].ycor()
    segmentos[index].goto(x,y)
    
if totalSeg &gt; 0:
    x = cabeza.xcor()
    y = cabeza.ycor()
    segmentos[0].goto(x,y)
    
mov()

for segmento in segmentos:
    if segmento.distance(cabeza) &lt; 20:
        time.sleep(1)
        cabeza.goto(0,0)
        cabeza.direction = "stop"
        
        for segmento in segmentos:
            segmento.goto(1000,1000)
            
        segmentos.clear

time.sleep(posponer)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/topic/20070/the-snake-game-in-python</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 20:40:12 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20070.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Sep 2020 15:11:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to The snake game in python on Mon, 28 Sep 2020 15:15:59 GMT]]></title><description><![CDATA[<p dir="auto">One question:   WHY?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58009</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58009</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 28 Sep 2020 15:15:59 GMT</pubDate></item></channel></rss>