Member 14992982 Ответов: 1

Как я могу вернуть игрока к началу игры, когда я нажму один из белых квадратов в этом коде?


import turtle
import math

wn = turtle.Screen()
wn.bgcolor("blue")
wn.tracer(3)

mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-50)
mypen.pendown()
mypen.pensize(3)
mypen.color("black")
for side in range(1):
    mypen.forward(600)
    mypen.left(90)
for side in range(1):
    mypen.forward(415)
    mypen.left(90)
for side in range(1):
    mypen.forward(600)
    mypen.left(90)
for side in range(1):
    mypen.forward(415)
    mypen.left(90)
for side in range(1):
    mypen.right(45)
    mypen.forward(424)
    mypen.left(90)
    mypen.forward(424)
mypen.hideturtle()

player = turtle.Turtle()
player.color("red")
player.shape("circle")
player.penup()
player.speed(0)
player.setposition(-225, 50)

square = turtle.Turtle()
square.color("white")
square.shape("square")
square.penup()
square.speed(0)
square.setposition(-200, 100)

square_2 = turtle.Turtle()
square_2.color("white")
square_2.shape("square")
square_2.penup()
square_2.speed(0)
square_2.setposition(-250, 50)

square_3 = turtle.Turtle()
square_3.color("white")
square_3.shape("square")
square_3.penup()
square_3.speed(0)
square_3.setposition(-150, 0)

square_4 = turtle.Turtle()
square_4.color("white")
square_4.shape("square")
square_4.penup()
square_4.speed(0)
square_4.setposition(-200, 0)

square_5 = turtle.Turtle()
square_5.color("white")
square_5.shape("square")
square_5.penup()
square_5.speed(0)
square_5.setposition(-250, 100)

square_6 = turtle.Turtle()
square_6.color("white")
square_6.shape("square")
square_6.penup()
square_6.speed(0)
square_6.setposition(-50, 0)

square_7 = turtle.Turtle()
square_7.color("white")
square_7.shape("square")
square_7.penup()
square_7.speed(0)
square_7.setposition(0, -25)

square_8 = turtle.Turtle()
square_8.color("white")
square_8.shape("square")
square_8.penup()
square_8.speed(0)
square_8.setposition(0, 25)

square_9 = turtle.Turtle()
square_9.color("white")
square_9.shape("square")
square_9.penup()
square_9.speed(0)
square_9.setposition(175, 0)

square_10 = turtle.Turtle()
square_10.color("white")
square_10.shape("square")
square_10.penup()
square_10.speed(0)
square_10.setposition(200, 0)

square_11 = turtle.Turtle()
square_11.color("white")
square_11.shape("square")
square_11.penup()
square_11.speed(0)
square_11.setposition(100, -25)

square_12 = turtle.Turtle()
square_12.color("white")
square_12.shape("square")
square_12.penup()
square_12.speed(0)
square_12.setposition(150, 50)

square_13 = turtle.Turtle()
square_13.color("white")
square_13.shape("square")
square_13.penup()
square_13.speed(0)
square_13.setposition(100, 25)

square_14 = turtle.Turtle()
square_14.color("white")
square_14.shape("square")
square_14.penup()
square_14.speed(0)
square_14.setposition(50, 0)

square_15 = turtle.Turtle()
square_15.color("white")
square_15.shape("square")
square_15.penup()
square_15.speed(0)
square_15.setposition(150, 0)

square_16 = turtle.Turtle()
square_16.color("white")
square_16.shape("square")
square_16.penup()
square_16.speed(0)
square_16.setposition(200, 75)

square_17 = turtle.Turtle()
square_17.color("white")
square_17.shape("square")
square_17.penup()
square_17.speed(0)
square_17.setposition(250, 75)

square_18 = turtle.Turtle()
square_18.color("white")
square_18.shape("square")
square_18.penup()
square_18.speed(0)
square_18.setposition(225, 125)

square_19 = turtle.Turtle()
square_19.color("white")
square_19.shape("square")
square_19.penup()
square_19.speed(0)
square_19.setposition(175, 125)

square_20 = turtle.Turtle()
square_20.color("white")
square_20.shape("square")
square_20.penup()
square_20.speed(0)
square_20.setposition(200, 175)

square_21 = turtle.Turtle()
square_21.color("white")
square_21.shape("square")
square_21.penup()
square_21.speed(0)
square_21.setposition(225, 225)

square_22 = turtle.Turtle()
square_22.color("white")
square_22.shape("square")
square_22.penup()
square_22.speed(0)
square_22.setposition(250, 0)

square_23 = turtle.Turtle()
square_23.color("white")
square_23.shape("square")
square_23.penup()
square_23.speed(0)
square_23.setposition(250, 25)

square_24 = turtle.Turtle()
square_24.color("white")
square_24.shape("square")
square_24.penup()
square_24.speed(0)
square_24.setposition(250, 50)

square_25 = turtle.Turtle()
square_25.color("white")
square_25.shape("square")
square_25.penup()
square_25.speed(0)
square_25.setposition(200, 275)

square_26 = turtle.Turtle()
square_26.color("white")
square_26.shape("square")
square_26.penup()
square_26.speed(0)
square_26.setposition(250, 275)

square_27 = turtle.Turtle()
square_27.color("white")
square_27.shape("square")
square_27.penup()
square_27.speed(0)
square_27.setposition(225, 325)

square_28 = turtle.Turtle()
square_28.color("white")
square_28.shape("square")
square_28.penup()
square_28.speed(0)
square_28.setposition(175, 325)

square_29 = turtle.Turtle()
square_29.color("white")
square_29.shape("square")
square_29.penup()
square_29.speed(0)
square_29.setposition(-150, 100)

square_30 = turtle.Turtle()
square_30.color("white")
square_30.shape("square")
square_30.penup()
square_30.speed(0)
square_30.setposition(-100, 25)

square_31 = turtle.Turtle()
square_31.color("white")
square_31.shape("square")
square_31.penup()
square_31.speed(0)
square_31.setposition(-100, 75)

square_32 = turtle.Turtle()
square_32.color("white")
square_32.shape("square")
square_32.penup()
square_32.speed(0)
square_32.setposition(200, 50)

square_33 = turtle.Turtle()
square_33.color("white")
square_33.shape("square")
square_33.penup()
square_33.speed(0)
square_33.setposition(225, 0)

square_34 = turtle.Turtle()
square_34.color("white")
square_34.shape("square")
square_34.penup()
square_34.speed(0)
square_34.setposition(250, 100)

square_35 = turtle.Turtle()
square_35.color("white")
square_35.shape("square")
square_35.penup()
square_35.speed(0)
square_35.setposition(250, 200)

square_36 = turtle.Turtle()
square_36.color("white")
square_36.shape("square")
square_36.penup()
square_36.speed(0)
square_36.setposition(250, 125)

square_37 = turtle.Turtle()
square_37.color("white")
square_37.shape("square")
square_37.penup()
square_37.speed(0)
square_37.setposition(250, 150)

square_38 = turtle.Turtle()
square_38.color("white")
square_38.shape("square")
square_38.penup()
square_38.speed(0)
square_38.setposition(250, 175)

square_39 = turtle.Turtle()
square_39.color("white")
square_39.shape("square")
square_39.penup()
square_39.speed(0)
square_39.setposition(250, 225)

square_40 = turtle.Turtle()
square_40.color("white")
square_40.shape("square")
square_40.penup()
square_40.speed(0)
square_40.setposition(250, 300)

square_41 = turtle.Turtle()
square_41.color("white")
square_41.shape("square")
square_41.penup()
square_41.speed(0)
square_41.setposition(250, 250)

square_42 = turtle.Turtle()
square_42.color("white")
square_42.shape("square")
square_42.penup()
square_42.speed(0)
square_42.setposition(250, 325)

square_43 = turtle.Turtle()
square_43.color("white")
square_43.shape("square")
square_43.penup()
square_43.speed(0)
square_43.setposition(175, 300)

square_44 = turtle.Turtle()
square_44.color("white")
square_44.shape("square")
square_44.penup()
square_44.speed(0)
square_44.setposition(175, 275)

square_45 = turtle.Turtle()
square_45.color("white")
square_45.shape("square")
square_45.penup()
square_45.speed(0)
square_45.setposition(175, 250)

square_46 = turtle.Turtle()
square_46.color("white")
square_46.shape("square")
square_46.penup()
square_46.speed(0)
square_46.setposition(175, 225)

square_47 = turtle.Turtle()
square_47.color("white")
square_47.shape("square")
square_47.penup()
square_47.speed(0)
square_47.setposition(175, 200)

square_48 = turtle.Turtle()
square_48.color("white")
square_48.shape("square")
square_48.penup()
square_48.speed(0)
square_48.setposition(175, 175)

square_49 = turtle.Turtle()
square_49.color("white")
square_49.shape("square")
square_49.penup()
square_49.speed(0)
square_49.setposition(175, 150)

square_50 = turtle.Turtle()
square_50.color("white")
square_50.shape("square")
square_50.penup()
square_50.speed(0)
square_50.setposition(175, 100)

square_51 = turtle.Turtle()
square_51.color("white")
square_51.shape("square")
square_51.penup()
square_51.speed(0)
square_51.setposition(175, 75)

square_52 = turtle.Turtle()
square_52.color("white")
square_52.shape("square")
square_52.penup()
square_52.speed(0)
square_52.setposition(175, 50)

square_53 = turtle.Turtle()
square_53.color("white")
square_53.shape("square")
square_53.penup()
square_53.speed(0)
square_53.setposition(50, 50)

square_54 = turtle.Turtle()
square_54.color("white")
square_54.shape("square")
square_54.penup()
square_54.speed(0)
square_54.setposition(75, 50)

square_55 = turtle.Turtle()
square_55.color("white")
square_55.shape("square")
square_55.penup()
square_55.speed(0)
square_55.setposition(100, 50)

square_56 = turtle.Turtle()
square_56.color("white")
square_56.shape("square")
square_56.penup()
square_56.speed(0)
square_56.setposition(125, 50)

square_57 = turtle.Turtle()
square_57.color("white")
square_57.shape("square")
square_57.penup()
square_57.speed(0)
square_57.setposition(0, 50)

square_58 = turtle.Turtle()
square_58.color("white")
square_58.shape("square")
square_58.penup()
square_58.speed(0)
square_58.setposition(25, 50)

square_59 = turtle.Turtle()
square_59.color("white")
square_59.shape("square")
square_59.penup()
square_59.speed(0)
square_59.setposition(-25, 50)

square_60 = turtle.Turtle()
square_60.color("white")
square_60.shape("square")
square_60.penup()
square_60.speed(0)
square_60.setposition(-50, 50)

square_61 = turtle.Turtle()
square_61.color("white")
square_61.shape("square")
square_61.penup()
square_61.speed(0)
square_61.setposition(-75, 50)

square_62 = turtle.Turtle()
square_62.color("white")
square_62.shape("square")
square_62.penup()
square_62.speed(0)
square_62.setposition(-100, 50)

square_63 = turtle.Turtle()
square_63.color("white")
square_63.shape("square")
square_63.penup()
square_63.speed(0)
square_63.setposition(-100, 100)

square_64 = turtle.Turtle()
square_64.color("white")
square_64.shape("square")
square_64.penup()
square_64.speed(0)
square_64.setposition(-125, 100)

square_65 = turtle.Turtle()
square_65.color("white")
square_65.shape("square")
square_65.penup()
square_65.speed(0)
square_65.setposition(-175, 100)

square_66 = turtle.Turtle()
square_66.color("white")
square_66.shape("square")
square_66.penup()
square_66.speed(0)
square_66.setposition(-225, 100)

square_67 = turtle.Turtle()
square_67.color("white")
square_67.shape("square")
square_67.penup()
square_67.speed(0)
square_67.setposition(-250, 75)

square_68 = turtle.Turtle()
square_68.color("white")
square_68.shape("square")
square_68.penup()
square_68.speed(0)
square_68.setposition(-250, 25)

square_69 = turtle.Turtle()
square_69.color("white")
square_69.shape("square")
square_69.penup()
square_69.speed(0)
square_69.setposition(-225, 0)

square_70 = turtle.Turtle()
square_70.color("white")
square_70.shape("square")
square_70.penup()
square_70.speed(0)
square_70.setposition(-175, 0)

square_71 = turtle.Turtle()
square_71.color("white")
square_71.shape("square")
square_71.penup()
square_71.speed(0)
square_71.setposition(-150, -25)

square_72 = turtle.Turtle()
square_72.color("white")
square_72.shape("square")
square_72.penup()
square_72.speed(0)
square_72.setposition(-125, -25)

square_73 = turtle.Turtle()
square_73.color("white")
square_73.shape("square")
square_73.penup()
square_73.speed(0)
square_73.setposition(-100, -25)

square_74 = turtle.Turtle()
square_74.color("white")
square_74.shape("square")
square_74.penup()
square_74.speed(0)
square_74.setposition(-75, -25)

square_75 = turtle.Turtle()
square_75.color("white")
square_75.shape("square")
square_75.penup()
square_75.speed(0)
square_75.setposition(-25, -25)

square_76 = turtle.Turtle()
square_76.color("white")
square_76.shape("square")
square_76.penup()
square_76.speed(0)
square_76.setposition(50, -25)

square_77 = turtle.Turtle()
square_77.color("white")
square_77.shape("square")
square_77.penup()
square_77.speed(0)
square_77.setposition(75, -25)

square_78 = turtle.Turtle()
square_78.color("white")
square_78.shape("square")
square_78.penup()
square_78.speed(0)
square_78.setposition(-50, -25)

square_79 = turtle.Turtle()
square_79.color("white")
square_79.shape("square")
square_79.penup()
square_79.speed(0)
square_79.setposition(125, -25)

square_80 = turtle.Turtle()
square_80.color("white")
square_80.shape("square")
square_80.penup()
square_80.speed(0)
square_80.setposition(25, -25)

square_81 = turtle.Turtle()
square_81.color("white")
square_81.shape("square")
square_81.penup()
square_81.speed(0)
square_81.setposition(150, -25)

square_82 = turtle.Turtle()
square_82.color("white")
square_82.shape("square")
square_82.penup()
square_82.speed(0)
square_82.setposition(-250, 0)

speed = 0.4

def turnleft():
    player.left(90)

def turnright():
    player.right(90)

turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")

while True:
    player.forward(speed)

    if player.xcor() > 290 or player.xcor() < -290:
        player.goto(-50,-200)

    if player.ycor() > 358 or player.ycor() < -40:
        player.goto(-50,-200)

    d = math.sqrt(math.pow(player.xcor()-square.xcor(),2) + math.pow(player.ycor()-square.ycor(),2))
    if d < 20:
        square.q()

    d = math.sqrt(math.pow(player.xcor()-square_2.xcor(),2) + math.pow(player.ycor()-square_2.ycor(),2))
    if d < 20:
        square_2.q()

    d = math.sqrt(math.pow(player.xcor()-square_3.xcor(),2) + math.pow(player.ycor()-square_3.ycor(),2))
    if d < 20:
        square_3.q()

    d = math.sqrt(math.pow(player.xcor()-square_4.xcor(),2) + math.pow(player.ycor()-square_4.ycor(),2))
    if d < 20:
        square_4.q()

    d = math.sqrt(math.pow(player.xcor()-square_5.xcor(),2) + math.pow(player.ycor()-square_5.ycor(),2))
    if d < 20:
        square_5.q()

    d = math.sqrt(math.pow(player.xcor()-square_6.xcor(),2) + math.pow(player.ycor()-square_6.ycor(),2))
    if d < 20:
        square_6.q()

    d = math.sqrt(math.pow(player.xcor()-square_7.xcor(),2) + math.pow(player.ycor()-square_7.ycor(),2))
    if d < 20:
        square_7.q()

    d = math.sqrt(math.pow(player.xcor()-square_8.xcor(),2) + math.pow(player.ycor()-square_8.ycor(),2))
    if d < 20:
        square_8.q()

    d = math.sqrt(math.pow(player.xcor()-square_9.xcor(),2) + math.pow(player.ycor()-square_9.ycor(),2))
    if d < 20:
        square_9.q()

    d = math.sqrt(math.pow(player.xcor()-square_10.xcor(),2) + math.pow(player.ycor()-square_10.ycor(),2))
    if d < 20:
        square_10.q()

    d = math.sqrt(math.pow(player.xcor()-square_11.xcor(),2) + math.pow(player.ycor()-square_11.ycor(),2))
    if d < 20:
        square_11.q()

    d = math.sqrt(math.pow(player.xcor()-square_12.xcor(),2) + math.pow(player.ycor()-square_12.ycor(),2))
    if d < 20:
        square_12.q()

    d = math.sqrt(math.pow(player.xcor()-square_13.xcor(),2) + math.pow(player.ycor()-square_13.ycor(),2))
    if d < 20:
        square_13.q()

    d = math.sqrt(math.pow(player.xcor()-square_14.xcor(),2) + math.pow(player.ycor()-square_14.ycor(),2))
    if d < 20:
        square_14.q()

    d = math.sqrt(math.pow(player.xcor()-square_15.xcor(),2) + math.pow(player.ycor()-square_15.ycor(),2))
    if d < 20:
        square_15.q()

    d = math.sqrt(math.pow(player.xcor()-square_16.xcor(),2) + math.pow(player.ycor()-square_16.ycor(),2))
    if d < 20:
        square_16.q()

    d = math.sqrt(math.pow(player.xcor()-square_17.xcor(),2) + math.pow(player.ycor()-square_17.ycor(),2))
    if d < 20:
        square_17.q()

    d = math.sqrt(math.pow(player.xcor()-square_18.xcor(),2) + math.pow(player.ycor()-square_18.ycor(),2))
    if d < 20:
        square_18.q()

    d = math.sqrt(math.pow(player.xcor()-square_19.xcor(),2) + math.pow(player.ycor()-square_19.ycor(),2))
    if d < 20:
        square_19.q()

    d = math.sqrt(math.pow(player.xcor()-square_20.xcor(),2) + math.pow(player.ycor()-square_20.ycor(),2))
    if d < 20:
        square_20.q()

    d = math.sqrt(math.pow(player.xcor()-square_21.xcor(),2) + math.pow(player.ycor()-square_21.ycor(),2))
    if d < 20:
        square_21.q()

    d = math.sqrt(math.pow(player.xcor()-square_22.xcor(),2) + math.pow(player.ycor()-square_22.ycor(),2))
    if d < 20:
        square_22.q()

    d = math.sqrt(math.pow(player.xcor()-square_23.xcor(),2) + math.pow(player.ycor()-square_23.ycor(),2))
    if d < 20:
        square_23.q()

    d = math.sqrt(math.pow(player.xcor()-square_24.xcor(),2) + math.pow(player.ycor()-square_24.ycor(),2))
    if d < 20:
        square_24.q()

    d = math.sqrt(math.pow(player.xcor()-square_25.xcor(),2) + math.pow(player.ycor()-square_25.ycor(),2))
    if d < 20:
        square_25.q()

    d = math.sqrt(math.pow(player.xcor()-square_26.xcor(),2) + math.pow(player.ycor()-square_26.ycor(),2))
    if d < 20:
        square_26.q()

    d = math.sqrt(math.pow(player.xcor()-square_27.xcor(),2) + math.pow(player.ycor()-square_27.ycor(),2))
    if d < 20:
        square_27.q()

    d = math.sqrt(math.pow(player.xcor()-square_28.xcor(),2) + math.pow(player.ycor()-square_28.ycor(),2))
    if d < 20:
        square_28.q()

    d = math.sqrt(math.pow(player.xcor()-square_29.xcor(),2) + math.pow(player.ycor()-square_29.ycor(),2))
    if d < 20:
        square_29.q()

    d = math.sqrt(math.pow(player.xcor()-square_30.xcor(),2) + math.pow(player.ycor()-square_30.ycor(),2))
    if d < 20:
        square_30.q()

    d = math.sqrt(math.pow(player.xcor()-square_31.xcor(),2) + math.pow(player.ycor()-square_31.ycor(),2))
    if d < 20:
        square_31.q()

    d = math.sqrt(math.pow(player.xcor()-square_32.xcor(),2) + math.pow(player.ycor()-square_32.ycor(),2))
    if d < 20:
        square_32.q()

    d = math.sqrt(math.pow(player.xcor()-square_33.xcor(),2) + math.pow(player.ycor()-square_33.ycor(),2))
    if d < 20:
        square_33.q()

    d = math.sqrt(math.pow(player.xcor()-square_34.xcor(),2) + math.pow(player.ycor()-square_34.ycor(),2))
    if d < 20:
        square_34.q()

    d = math.sqrt(math.pow(player.xcor()-square_35.xcor(),2) + math.pow(player.ycor()-square_35.ycor(),2))
    if d < 20:
        square_35.q()

    d = math.sqrt(math.pow(player.xcor()-square_36.xcor(),2) + math.pow(player.ycor()-square_36.ycor(),2))
    if d < 20:
        square_36.q()

    d = math.sqrt(math.pow(player.xcor()-square_37.xcor(),2) + math.pow(player.ycor()-square_37.ycor(),2))
    if d < 20:
        square_37.q()

    d = math.sqrt(math.pow(player.xcor()-square_38.xcor(),2) + math.pow(player.ycor()-square_38.ycor(),2))
    if d < 20:
        square_38.q()

    d = math.sqrt(math.pow(player.xcor()-square_39.xcor(),2) + math.pow(player.ycor()-square_39.ycor(),2))
    if d < 20:
        square_39.q()

    d = math.sqrt(math.pow(player.xcor()-square_40.xcor(),2) + math.pow(player.ycor()-square_40.ycor(),2))
    if d < 20:
        square_40.q()

    d = math.sqrt(math.pow(player.xcor()-square_41.xcor(),2) + math.pow(player.ycor()-square_41.ycor(),2))
    if d < 20:
        square_41.q()

    d = math.sqrt(math.pow(player.xcor()-square_42.xcor(),2) + math.pow(player.ycor()-square_42.ycor(),2))
    if d < 20:
        square_42.q()

    d = math.sqrt(math.pow(player.xcor()-square_43.xcor(),2) + math.pow(player.ycor()-square_43.ycor(),2))
    if d < 20:
        square_43.q()

    d = math.sqrt(math.pow(player.xcor()-square_44.xcor(),2) + math.pow(player.ycor()-square_44.ycor(),2))
    if d < 20:
        square_44.q()

    d = math.sqrt(math.pow(player.xcor()-square_45.xcor(),2) + math.pow(player.ycor()-square_45.ycor(),2))
    if d < 20:
        square_45.q()

    d = math.sqrt(math.pow(player.xcor()-square_46.xcor(),2) + math.pow(player.ycor()-square_46.ycor(),2))
    if d < 20:
        square_46.q()

    d = math.sqrt(math.pow(player.xcor()-square_47.xcor(),2) + math.pow(player.ycor()-square_47.ycor(),2))
    if d < 20:
        square_47.q()

    d = math.sqrt(math.pow(player.xcor()-square_48.xcor(),2) + math.pow(player.ycor()-square_48.ycor(),2))
    if d < 20:
        square_48.q()

    d = math.sqrt(math.pow(player.xcor()-square_49.xcor(),2) + math.pow(player.ycor()-square_49.ycor(),2))
    if d < 20:
        square_49.q()

    d = math.sqrt(math.pow(player.xcor()-square_50.xcor(),2) + math.pow(player.ycor()-square_50.ycor(),2))
    if d < 20:
        square_50.q()

    d = math.sqrt(math.pow(player.xcor()-square_51.xcor(),2) + math.pow(player.ycor()-square_51.ycor(),2))
    if d < 20:
        square_51.q()

    d = math.sqrt(math.pow(player.xcor()-square_52.xcor(),2) + math.pow(player.ycor()-square_52.ycor(),2))
    if d < 20:
        square_52.q()

    d = math.sqrt(math.pow(player.xcor()-square_53.xcor(),2) + math.pow(player.ycor()-square_53.ycor(),2))
    if d < 20:
        square_53.q()

    d = math.sqrt(math.pow(player.xcor()-square_54.xcor(),2) + math.pow(player.ycor()-square_54.ycor(),2))
    if d < 20:
        square_54.q()

    d = math.sqrt(math.pow(player.xcor()-square_55.xcor(),2) + math.pow(player.ycor()-square_55.ycor(),2))
    if d < 20:
        square_55.q()

    d = math.sqrt(math.pow(player.xcor()-square_56.xcor(),2) + math.pow(player.ycor()-square_56.ycor(),2))
    if d < 20:
        square_56.q()

    d = math.sqrt(math.pow(player.xcor()-square_57.xcor(),2) + math.pow(player.ycor()-square_57.ycor(),2))
    if d < 20:
        square_57.q()

    d = math.sqrt(math.pow(player.xcor()-square_58.xcor(),2) + math.pow(player.ycor()-square_58.ycor(),2))
    if d < 20:
        square_58.q()

    d = math.sqrt(math.pow(player.xcor()-square_59.xcor(),2) + math.pow(player.ycor()-square_59.ycor(),2))
    if d < 20:
        square_59.q()

    d = math.sqrt(math.pow(player.xcor()-square_60.xcor(),2) + math.pow(player.ycor()-square_60.ycor(),2))
    if d < 20:
        square_60.q()

    d = math.sqrt(math.pow(player.xcor()-square_61.xcor(),2) + math.pow(player.ycor()-square_61.ycor(),2))
    if d < 20:
        square_61.q()

    d = math.sqrt(math.pow(player.xcor()-square_62.xcor(),2) + math.pow(player.ycor()-square_62.ycor(),2))
    if d < 20:
        square_62.q()

    d = math.sqrt(math.pow(player.xcor()-square_63.xcor(),2) + math.pow(player.ycor()-square_63.ycor(),2))
    if d < 20:
        square_63.q()

    d = math.sqrt(math.pow(player.xcor()-square_64.xcor(),2) + math.pow(player.ycor()-square_64.ycor(),2))
    if d < 20:
        square_64.q()

    d = math.sqrt(math.pow(player.xcor()-square_65.xcor(),2) + math.pow(player.ycor()-square_65.ycor(),2))
    if d < 20:
        square_65.q()

    d = math.sqrt(math.pow(player.xcor()-square_66.xcor(),2) + math.pow(player.ycor()-square_66.ycor(),2))
    if d < 20:
        square_66.q()

    d = math.sqrt(math.pow(player.xcor()-square_67.xcor(),2) + math.pow(player.ycor()-square_67.ycor(),2))
    if d < 20:
        square_67.q()

    d = math.sqrt(math.pow(player.xcor()-square_68.xcor(),2) + math.pow(player.ycor()-square_68.ycor(),2))
    if d < 20:
        square_68.q()

    d = math.sqrt(math.pow(player.xcor()-square_69.xcor(),2) + math.pow(player.ycor()-square_69.ycor(),2))
    if d < 20:
        square_69.q()

    d = math.sqrt(math.pow(player.xcor()-square_70.xcor(),2) + math.pow(player.ycor()-square_70.ycor(),2))
    if d < 20:
        square_70.q()

    d = math.sqrt(math.pow(player.xcor()-square_71.xcor(),2) + math.pow(player.ycor()-square_71.ycor(),2))
    if d < 20:
        square_71.q()

    d = math.sqrt(math.pow(player.xcor()-square_72.xcor(),2) + math.pow(player.ycor()-square_72.ycor(),2))
    if d < 20:
        square_72.q()

    d = math.sqrt(math.pow(player.xcor()-square_73.xcor(),2) + math.pow(player.ycor()-square_73.ycor(),2))
    if d < 20:
        square_73.q()

    d = math.sqrt(math.pow(player.xcor()-square_74.xcor(),2) + math.pow(player.ycor()-square_74.ycor(),2))
    if d < 20:
        square_74.q()

    d = math.sqrt(math.pow(player.xcor()-square_75.xcor(),2) + math.pow(player.ycor()-square_75.ycor(),2))
    if d < 20:
        square_75.q()

    d = math.sqrt(math.pow(player.xcor()-square_76.xcor(),2) + math.pow(player.ycor()-square_76.ycor(),2))
    if d < 20:
        square_76.q()

    d = math.sqrt(math.pow(player.xcor()-square_77.xcor(),2) + math.pow(player.ycor()-square_77.ycor(),2))
    if d < 20:
        square_77.q()

    d = math.sqrt(math.pow(player.xcor()-square_78.xcor(),2) + math.pow(player.ycor()-square_78.ycor(),2))
    if d < 20:
        square_78.q()

    d = math.sqrt(math.pow(player.xcor()-square_79.xcor(),2) + math.pow(player.ycor()-square_79.ycor(),2))
    if d < 20:
        square_79.q()

    d = math.sqrt(math.pow(player.xcor()-square_80.xcor(),2) + math.pow(player.ycor()-square_80.ycor(),2))
    if d < 20:
        square_80.q()

    d = math.sqrt(math.pow(player.xcor()-square_81.xcor(),2) + math.pow(player.ycor()-square_81.ycor(),2))
    if d < 20:
        square_81.q()

    d = math.sqrt(math.pow(player.xcor()-square_82.xcor(),2) + math.pow(player.ycor()-square_82.ycor(),2))
    if d < 20:
        square_82.q()       


Что я уже пробовал:

Я пытался понять это, но ничего не понимаю.

Richard MacCutchan

Вам нужно научиться использовать массивы и списки, циклы и функции. Дублирование кода делает это кошмаром для поддержания.

1 Ответов

Рейтинг:
12

Gerry Schmitz

Получите позицию в начале и сохраните ее. Когда вам нужно будет вернуться "назад", установите позицию на ту, которую вы сохранили.

Получить позицию черепахи в Python - Stack Overflow[^]


Member 14992982

Но что же мне тогда писать, в этом коде?

д = математика.корень(математика.военнопленных(плеер.xcor()-square_17.xcor(),2) + математика.военнопленных(плеер.ycor()-square_17.ycor(),2))
если d < 20:
square_17.вопрос()

Gerry Schmitz

Какое это имеет отношение к "возвращению"? Ваш вопрос здесь сводится к следующему: "а как насчет этого?". А как насчет "чего"?

Member 14992982

Потому что функция, которую я имею на этом коде, говорит, что программа должна перестать работать, когда игрок нажмет один из белых квадратов. Итак, что я должен напечатать, чтобы заставить игрока вернуться к началу и двигаться вперед со скоростью? Когда он попал в один из белых квадратов?