Answer the question
In order to leave comments, you need to log in
Turtle not responding when running while loop, how to fix?
from turtle import *
from random import randint
class Game(Turtle):
def __init__(self,x,y,step = 10, shape = "circle", color = "black"):
super().__init__()
self.penup()
self.speed(0)
self.goto(x,y)
self.color(color)
self.shape(shape)
self.step = step
def move_up(self):
self.goto(self.xcor(), self.ycor() + 10)
def move_down(self):
self.goto(self.xcor(), self.ycor() - 10)
def move_left(self):
self.goto(self.xcor() - 10, self.ycor())
def move_right(self):
self.goto(self.xcor() + 10, self.ycor())
def Kasanie(self,Sprite1,Sprite2):
dis1 = self.distance(Sprite1.xcor(), Sprite1.ycor())
dis2 = self.distance(Sprite2.xcor(), Sprite2.ycor())
if dis1 < 30 or dis2 < 30:
return True
else:
return False
def Kasanie2(self,goal):
dis1 = self.distance(goal.xcor(), goal.ycor())
if dis1 < 30:
return True
else:
return False
player = Game(0, -100, 10, 'circle', 'orange')
Sprite1 = Game(-200, 200, 10, 'square', 'red')
Sprite2 = Game(200, 100, 10, 'square', 'red')
End = Game (0, 300, 10, 'triangle', 'Lime')
scr = player.getscreen()
scr.listen()
scr.onkey(player.move_up, "w")
scr.onkey(player.move_down, "s")
scr.onkey(player.move_left, "a")
scr.onkey(player.move_right, "d")
Inf1 = player.Kasanie(Sprite1,Sprite2)
Inf2 = player.Kasanie2(End)
total_score = 0
while total_score < 3:
if Inf1:
player.goto(0,-100)
total_score += 1
if Inf2:
End.hideturtle()
break
Sprite2.hideturtle()
Sprite1.hideturtle()
player.getscreen()._root.mainloop()
player.done()
Answer the question
In order to leave comments, you need to log in
In the first case, not a comparison , but an assignment . As a result, the value of the variable a is used in the condition , which is equal to 1 , which is converted to true .
In the second case, on the first line, you are doing a comparison , not an assignment . Therefore, in the second line, the variable $a has no value, that is, it is definitely not equal to 1 .
With php everything is ok, the problem is with your code.
I guess you'll find examples here that will help you build your game more successfully without those endless loops.
A possible problem is that the thread "walks" through the code and already checks the player's action:
scr.listen()
scr.onkey(player.move_up, "w")
scr.onkey(player.move_down, "s")
scr.onkey(player.move_left, "a")
scr.onkey(player.move_right, "d")
while total_score < 3:
if Inf1:
player.goto(0,-100)
total_score += 1
if Inf2:
End.hideturtle()
break
while total_score < 3:
if Inf1:
player.goto(0,-100)
total_score += 1
else:
End.hideturtle()
break
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question