Skip to main content
The game tracks two values: the current score (puntaje) and the session high score (puntajeAlto). Both are integers initialized to 0 at startup.
puntaje = 0
puntajeAlto = 0

Score

Increases by 10 each time the snake eats food. Resets to 0 on wall collision or self-collision. Displayed live on screen.

High score

Updated to match puntaje whenever puntaje exceeds it. Never resets during the session — only a new game run starts it from 0.

Earning points

A point event fires when serpiente.distance(comida) < 20. The score increments by 10:
if serpiente.distance(comida) < 20:
    # ... spawn new food and body segment ...
    puntaje += 10
    if puntaje > puntajeAlto:
        puntajeAlto = puntaje

Score display

The texto turtle renders both values as a single line at position (0, -260). Before each write, texto.clear() removes the previous text:
texto.write(
    f"Puntaje: {puntaje}\tPuntaje más alto: {puntajeAlto}",
    align="center",
    font=("verdana", 12, "normal")
)

When the display updates

There are three distinct cases where texto.clear() followed by texto.write() is called:

Food eaten — new high score

When puntaje exceeds puntajeAlto, the high score is updated and the display refreshes:
puntaje += 10
if puntaje > puntajeAlto:
    puntajeAlto = puntaje
    texto.clear()
    texto.write(f"Puntaje: {puntaje}\tPuntaje más alto: {puntajeAlto}",
    align="center",
    font=("verdana", 12, "normal"))
When puntaje is still below puntajeAlto, the score still goes up and the display refreshes to show the new current score:
if puntaje < puntajeAlto:
    texto.clear()
    texto.write(f"Puntaje: {puntaje}\tPuntaje más alto: {puntajeAlto}",
    align="center",
    font=("verdana", 12, "normal"))
On either type of collision, puntaje resets to 0 and the display updates. puntajeAlto is left unchanged:
puntaje = 0
texto.clear()
texto.write(f"Puntaje: {puntaje}\tPuntaje más alto: {puntajeAlto}",
align="center",
font=("verdana", 12, "normal"))
The high score is stored in memory only. Closing the game window or restarting the script resets puntajeAlto to 0. There is no file or database persistence between runs.

Build docs developers (and LLMs) love