击中目标乌龟

时间:2018-10-20 16:46:07

标签: python

如果射弹未击中目标,他们希望我们通过打印修改给我们的代码,希望我们指示是否需要调整力值或角度。我只是不了解代码,甚至不知道从哪里开始。这是给出的代码。

import turtle

SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600
TARGET_LLEFT_X = 100
TARGET_LLEFT_Y = 250
TARGET_WIDTH = 25
FORCE_FACTOR = 30
PROJECTILE_SPEED = 1
NORTH = 90
SOUTH = 270
EAST = 0
WEST = 180
turtle.setup(SCREEN_WIDTH, SCREEN_HEIGHT)
turtle.hideturtle()
turtle.speed(0)
turtle.penup()
turtle.goto(TARGET_LLEFT_X, TARGET_LLEFT_Y)
turtle.pendown()
turtle.setheading(EAST)
turtle.forward(TARGET_WIDTH)
turtle.setheading(NORTH)
turtle.forward(TARGET_WIDTH)
turtle.setheading(WEST)
turtle.forward(TARGET_WIDTH)
turtle.setheading(SOUTH)
turtle.forward(TARGET_WIDTH)
turtle.penup()
turtle.goto(0, 0)
turtle.setheading(EAST)
turtle.showturtle()
turtle.speed(PROJECTILE_SPEED)
angle = float(input("Enter the projectile's angle: "))
force = float(input("Enter the launch force (1-10): "))
distance = force * FORCE_FACTOR

turtle.setheading(angle)
turtle.pendown()
turtle.forward(distance)
if (turtle.xcor() >= TARGET_LLEFT_X and
    turtle.xcor() <= (TARGET_LLEFT_X + TARGET_WIDTH) and
    turtle.ycor() >= TARGET_LLEFT_Y and
    turtle.ycor() <= (TARGET_LLEFT_Y + TARGET_WIDTH)):
        print('Target hit!')


else:
    print('Target missed!')

0 个答案:

没有答案