Search code examples
pythonscoringpython-turtle

Python simple score (point) system on a simple game


I have produced a simple game using the turtle module. The objective of the game is to return to the original position in a certain number of moves, through left and right inputs. Therefore, I tried to make a scoring (point) system that counts the number of moves the user has done and prints a winning message if the user returns to the original position in the specified number of moves. If the user (player) fails to do so it prints a failure message. However, it doesn't count up each move (point) and when it prints the score it always prints "1" no matter how many moves the player has done. Apologies if the questions seem too simple but help is much appreciated.

Here is the code:

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()

Solution

  • The problem is the score = 0 call at the top of the loop. This resets the score at every loop iteration, so there's no way score could ever be anything other than 0 or 1.