我刚开始用蟒蛇,我想做一个小小的射箭游戏。然而,它在这一点上产生了一个错误:d=math.sqrt(x*x+y*y)(即新点和冰斗的原始中心之间的距离)有什么关于这不起作用的想法吗?
def archery():
win = GraphWin("Archery Game", 500,500)
win.setCoords(-50, -50, 50, 50)
circle1 = Circle(Point(0,0), 40)
circle1.setFill("white")
circle1.draw(win)
circle2 = Circle(Point(0,0), 35)
circle2.setFill("black")
circle2.draw(win)
circle3 = Circle(Point(0,0), 30)
circle3.setFill("blue")
circle3.draw(win)
circle4 = Circle(Point(0,0), 25)
circle4.setFill("red")
circle4.draw(win)
circle5 = Circle(Point(0,0), 20)
circle5.setFill("yellow")
circle5.draw(win)
score = 0
for i in range(5):
p = win.getMouse()
p.draw(win)
x = p.getX
y = p.getY
d = math.sqrt(x*x + y*y)
if 40 >= d > 35:
score = score + 1
elif 35 >= d > 30:
score = score + 3
elif 30 >= d > 25:
score = score + 5
elif 25 >= d > 20:
score = score + 7
elif 20 >= d >= 0:
score = score + 9
else:
score = score + 0
print("Your current score is:", score)
win.getMouse()
win.close()
最佳答案
x = p.getX
y = p.getY
将返回函数
getX
和getY
,而不是执行它。正如Mike Steder所说,trygetX()
,它应该返回一个值。关于python - Python中的简单射箭游戏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5108434/