【发布时间】:2020-09-25 23:03:15
【问题描述】:
我使用海龟模块制作了一个简单的游戏。游戏的目标是通过左右输入在一定数量的移动中返回到原始位置。因此,我尝试制作一个计分(积分)系统,该系统计算用户完成的移动次数,并在用户在指定移动次数内返回原始位置时打印获胜消息。如果用户(玩家)没有这样做,它会打印一条失败消息。但是,它不会计算每个移动(点),并且当它打印分数时,无论玩家做了多少移动,它总是打印“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()
【问题讨论】:
标签: python scoring python-turtle