Python简单记分(点)系统上的一个简单游戏
我用海龟模块制作了一个简单的游戏。游戏的目标是通过左右输入,在一定数量的移动中回到原始位置。因此,我尝试制作一个计分(积分)系统,该系统统计用户已完成的移动次数,如果用户以指定的移动次数返回到原始位置,则打印一条获胜消息。如果用户(玩家)未能这样做,它将打印一条失败消息。但是,它不会计算每一步(点数),当它打印分数时,无论玩家做了多少步,它都会打印“1”。如果问题看起来太简单,请道歉,但非常感谢您的帮助 代码如下:Python简单记分(点)系统上的一个简单游戏,python,scoring,python-turtle,Python,Scoring,Python Turtle,我用海龟模块制作了一个简单的游戏。游戏的目标是通过左右输入,在一定数量的移动中回到原始位置。因此,我尝试制作一个计分(积分)系统,该系统统计用户已完成的移动次数,如果用户以指定的移动次数返回到原始位置,则打印一条获胜消息。如果用户(玩家)未能这样做,它将打印一条失败消息。但是,它不会计算每一步(点数),当它打印分数时,无论玩家做了多少步,它都会打印“1”。如果问题看起来太简单,请道歉,但非常感谢您的帮助 代码如下: import turtle print("Try to return to o
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
不可能是0
或1
哦!我明白了,谢谢。我应该把它放在while循环之前吗?你应该只在游戏开始时将它设置为0。