simple archery game in python
I'm just starting out with python and I'm trying to make a little archery game. However, it creates an error at this point: d = math.sqrt(x*x + y*y) (i.e. the distance between the new point and the original center of the cirlce) Any ideas on why this doesn't work?
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
will return the function getX and getY instead of executing it. As Mike Steder said, try getX(), that should return a value.
First, you probably need to do:
x = p.getX()
y = p.getY()
i.e. call the functions and use the return value, instead of using the functions themselves.
Second, you can change the math.sqrt(x*x + y*y) call to:
d = math.hypot(x, y)
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论