#๐Ÿ”’ Score Upgrades

4 messages ยท Page 1 of 1 (latest)

shy monolith
#
import threading
import time


# Initialize the score
score = 0
running = True
sps = 1

def increment_score():
    """Automatically add 1 to the score every second."""
    global score, running
    while running:
        time.sleep(1)
        score += sps
        print(f"Score (auto): {score}")
        
def sps_upgrade_1():
    while running:
        if score > 25:
            while running:
                res = input("Would you like to spend 25 points to get +1 point a sec? (Y/N")
                if type(res) == str:
                    if res == "Y":
                        print("y")
                    elif res == "N":
                        print("n")
                    else:
                        print("Please type Y or N")
                else:
                    print("Input must be string")

def play_game():
    """Main game loop where the player presses 'f' to increase the score."""
    global score, running
    print("Press 'f' to increase your score! Press 'q' to quit.")

    # Start the auto-increment function in a separate thread
    auto_increment_thread = threading.Thread(target=increment_score)
    auto_increment_thread.start()

    # Main game loop
    try:
        while running:
            if input() == "f":  # Detect if the 'f' key is pressed
                score += 1
                print(f"Score: {score}")
   # Prevent multiple rapid presses from counting as one
            elif input() == "q":  # Quit the game if 'q' is pressed
                running = False
                print("Game Over!")
    except KeyboardInterrupt:
        running = False
        print("\nGame interrupted. Goodbye!")

    # Ensure the thread ends before exiting
    auto_increment_thread.join()


if __name__ == "__main__":
    play_game()

Hi, I am trying to make a clicker game. The click and sps is sorted but i wanted a way to (test) an upgrade function. i want it to appear when i have 25 score but i tried out different code and it didnt seem to work.

stable brookBOT
#

@shy monolith

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stable brookBOT
#

@shy monolith

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.