Python 简单游戏的简单分数(点)系统

Python simple score (point) system on a simple game

我使用海龟模块制作了一个简单的游戏。游戏的objective是通过左右输入,以一定的步数,return回到原来的位置。因此,我尝试制作一个计分(积分)系统,计算用户完成的移动次数,如果用户 returns 到达指定移动次数的原始位置,则打印获胜消息。如果用户(玩家)没有这样做,它会打印一条失败消息。但是,它不会计算每一步(点),当它打印分数时,无论玩家完成了多少步,它总是打印“1”。如果问题看起来太简单,我们深表歉意,但非常感谢您的帮助。

代码如下:

import turtle

print("Try to return to original position in exactly 12 moves")
my_turtle = turtle.Turtle()
fx = my_turtle.pos()
score = 0
tries = 12

def turtles():
    while True:
      score = 0
      directions = input("Enter which way the turtle goes: ")
      if directions == "Right" or directions == "R":
            my_turtle.right(90)
            my_turtle.forward(100)
            score += 1
            print(score)
            if fx == my_turtle.pos() and tries == score:
              print("Well done")
            elif fx == my_turtle.pos and tries > score or score > tries:
              print("Return to original position in exactly 12 moves")

      directions1 = input("Enter which way the turtle goes: ")
      if directions1 == "Left" or directions1 == "L":
            my_turtle.left(90)
            my_turtle.forward(100)
            score += 1
            print(score)
            if fx == my_turtle.pos() and tries == score:
              print("Well done")
            elif fx == my_turtle.pos and tries > score or score > tries:
              print("Return to original position in exactly 12 moves")

turtles()


turtle.done()

问题出在循环顶部的 score = 0 调用。这会在每次循环迭代时重置分数,因此 score 不可能是 01.

以外的任何其他内容