I am making a Snake game and it has a: "raise Terminator/turtle.Terminator" message.


Joined
Dec 17, 2021
Messages
1
Reaction score
0
I would like it to run the program and not terminate itself.
Here is the code:

#//Snake
#Import random for spawns, turle for graphics, time for pauses, and urllib for downloading icon
import random
import turtle
import time
import urllib.request

#//Downloading...
print("Downloading necessary files...")
#//Icon download
iconURL = "https://freepngimg.com/download/sym...-slitherio-pass-free-transparent-image-hq.png"
icon = urllib.request.urlretrieve(iconURL, 'c:/ProgramData/icon.png')
print()
print("Download complete")
print("Launching game...")

#//Window creation
wn = turtle.Screen()
wn.setup(width = 1.0, height = 1.0)
canvas = wn.getcanvas()
root = canvas.winfo_toplevel()
root.overrideredirect(1)
wn.title('Snake')
wn.bgcolor('olive drab')
wn.tracer(0)

#//Snake character creation
head = turtle.Turtle()
head.shape("square")
head.color("white")
head.penup()
head.goto(0, 0)
head.direction = "Stop"

#//Food spawn
food = turtle.Turtle()
colors = 'blue'
shapes = random.choice(['square', 'triangle', 'circle'])
food.speed(0)
food.shape(shapes)
food.color(colors)
food.penup()
food.goto(0, 100)

#//Movement creations
def up():
if head.direction != "down":
head.direction = "up"

def down():
if head.direction != "up":
head.direction = "down"

def left():
if head.direction != "right":
head.direction = "left"

def right():
if head.direction != "left":
head.direction = "right"

def slither():
if head.direction == "up":
y = head.ycor()
head.sety(y+20)
if head.direction == "down":
y = head.ycor()
head.sety(y-20)
if head.direction == "left":
x = head.xcor()
head.setx(x-20)
if head.direction == "right":
x = head.xcor()
head.setx(x+20)

#//Keypresses
wn.listen()
wn.onkeypress(up(), 'w')
wn.onkeypress(down(), 's')
wn.onkeypress(left(), 'a')
wn.onkeypress(right(), 'd')

#//Segments
segments = []
delay = 0.0

#//Gameplay
while True:
wn.update()
if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
time.sleep(1)
head.goto(0, 0)
head.direction = "stop"
colors = random.choice(['green', 'deep sky blue', 'dark slate blue'])
shapes = 'square'
for segment in segments:
segment.goto(1000, 1000)
segments.clear()
delay = 0.1

if head.distance(food) < 20:
x = random.randint(-270, 270)
y = random.randint(-270, 270)
food.gotot(x, y)
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("orange")
new_segment.penup()
segments.append(new_segment)
delay -= 0.001

for index in range(len(segments)-1, 0, -1):
x = segments[index-1].xcor()
y = segments[index-1].ycor()
segments[index].goto(x, y)
if len(segments) > 0:
x = head.xcor()
y = head.ycor()
segments[0].goto(x, y)
move()
for segment in segments:
if segment.distance(head) < 20:
time.sleep(1)
head.goto(0, 0)
head.direction = "stop"
colors = random.choice(['red', 'blue', 'green'])
shapes = random.choice(['square', 'circle'])
for segment in segments:
segment.goto(1000, 1000)
segment.clear()
time.sleep(delay)

wn.mainloop()


It has this error message:

Traceback (most recent call last):
File "C:\Users\------\Downloads\Snake.py", line 89, in <module>
wn.update()
File "C:\Users\-----\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1304, in update
t._update_data()
File "C:\Users\-----\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2647, in _update_data
self.screen._incrementudc()
File "C:\Users\-----\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1293, in _incrementudc
raise Terminator
turtle.Terminator
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
174
Reaction score
19
Hello and welcome! Can you please post the code again, but in a code tag so that it keeps the indentation?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top