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

问题描述 投票:1回答:1

我使用turtle模块制作了一个简单的游戏。游戏的目的是通过左右输入以一定的步数返回到原始位置。因此,我试图建立一个计分(点)系统,该系统会计算用户已完成的移动次数,如果用户以指定的移动次数返回原始位置,则会显示获胜消息。如果用户(播放器)失败,则打印失败消息。但是,它不会计算每个动作(点),并且在打印分数时,无论玩家进行了多少移动,它始终会打印“ 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
1个回答
1
投票

问题是循环顶部的score = 0调用。这会在每次循环迭代时重置分数,因此score不可能是01之外的任何其他东西。

© www.soinside.com 2019 - 2024. All rights reserved.