基于乌龟的位置确定点数

我有一个Python程序,我需要获得一些陈述,以便我可以根据乌龟的位置获得积分。

我的代码:

import turtle
turtle.color("black")
turtle.circle(100)
print(turtle.xcor(), turtle.ycor())
turtle.left(90)
turtle.penup()
turtle.forward(20)
turtle.right(90)
turtle.pendown()
turtle.begin_fill()
turtle.circle(80)
print(turtle.xcor(), turtle.ycor())
turtle.end_fill()
turtle.left(90)
turtle.penup()
turtle.forward(20)
turtle.right(90)
turtle.pendown()
turtle.color("blue")
turtle.begin_fill()
turtle.circle(60)
print(turtle.xcor(), turtle.ycor())
turtle.end_fill()
turtle.left(90)
turtle.penup()
turtle.forward(20)
turtle.right(90)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
turtle.circle(40)
print(turtle.xcor(), turtle.ycor())
turtle.end_fill()
turtle.left(90)
turtle.penup()
turtle.forward(20)
turtle.right(90)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.circle(20)
print(turtle.xcor(), turtle.ycor())
turtle.end_fill()
turtle.penup()
turtle.forward(20)
turtle.pendown()
turtle.color("green")
turtle.dot()
turtle.hideturtle()

你可以帮我帮助我如何根据乌龟的立场获得积分?

回答 2

  1. 赞同 0

    在描述中描述文件.你应该使用turtle.pos()将当前位置返回VEC2D.

    BTABANTS
  2. 赞同 0

    在文件的文件中Turtle Graphics.您确实可以找到如何获得乌龟目前所在点的坐标:

    turtle.position()Oor.turtle.pos()得到这一点(x,y)COORDINATES。

    turtle.xcor()returns龟xCoorth。

    turtle.ycor()Returns龟的y coordinate.

    If you want to calculate a score depending on how close to the center of the drawn circle you are, simply calculate the distance of these coordinates to the distance of the coordinates of the center of the circle using a simple Mathemalical公式.

    Kim男士