- 8 Şub 2022
- 24
- 1
- 3
yılan oyununu yapmayı başardım ancak yılan hareket etmiyor bunu nasıl çözebilirim? 1q648ug.png
import turtle
import time
wn = turtle.Screen()
wn.title("Yılan Oyunu")
wn.bgcolor("black")
wn.setup(width=600, height=600)
# Yılan kafasını oluştur
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("purple")
head.penup()
head.goto(0,0)
head.direction = "stop"
# Yılan gövdesini oluştur
segments = []
# Hareket fonksiyonlarını oluştur
def go_up():
if head.direction != "down":
head.direction = "up"
def go_down():
if head.direction != "up":
head.direction = "down"
def go_left():
if head.direction != "right":
head.direction = "left"
def go_right():
if head.direction != "left":
head.direction = "right"
def move():
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)
# Klavye dinleyicilerini oluştur
wn.listen()
wn.onkeypress(go_up, "Up")
wn.onkeypress(go_down, "Down")
wn.onkeypress(go_left, "Left")
wn.onkeypress(go_right, "Right")
# Oyun döngüsü
while True:
wn.update()
# Yılanın duvarla çarpması durumunu kontrol et
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"
# Yılan gövdesini sil
for segment in segments:
segment.goto(1000, 1000)
# Yılan gövdesi listesini temizle
segments.clear()
# Hareket et
move(200)
# Yılan gövdesini oluştur
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("grey")
new_segment.penup()
segments.append(new_segment)
# Yılan gövdesinin
import turtle
import time
wn = turtle.Screen()
wn.title("Yılan Oyunu")
wn.bgcolor("black")
wn.setup(width=600, height=600)
# Yılan kafasını oluştur
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("purple")
head.penup()
head.goto(0,0)
head.direction = "stop"
# Yılan gövdesini oluştur
segments = []
# Hareket fonksiyonlarını oluştur
def go_up():
if head.direction != "down":
head.direction = "up"
def go_down():
if head.direction != "up":
head.direction = "down"
def go_left():
if head.direction != "right":
head.direction = "left"
def go_right():
if head.direction != "left":
head.direction = "right"
def move():
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)
# Klavye dinleyicilerini oluştur
wn.listen()
wn.onkeypress(go_up, "Up")
wn.onkeypress(go_down, "Down")
wn.onkeypress(go_left, "Left")
wn.onkeypress(go_right, "Right")
# Oyun döngüsü
while True:
wn.update()
# Yılanın duvarla çarpması durumunu kontrol et
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"
# Yılan gövdesini sil
for segment in segments:
segment.goto(1000, 1000)
# Yılan gövdesi listesini temizle
segments.clear()
# Hareket et
move(200)
# Yılan gövdesini oluştur
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("grey")
new_segment.penup()
segments.append(new_segment)
# Yılan gövdesinin