Python Forum

Full Version: DIY Escape Room for fun
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently working on a timer and pincode script which should determine whether someone is able to stop the timer in time by inserting the correct code so that the person wins the escape room. I created my escape room in real life. The only thing I want to add to my script is a live count down of the time instead of just showing the time left after someone tried a pincode.

import time
from datetime import timedelta, datetime


def countdown(t):
    while t:  # while t > 0 for clarity
        mins = t // 60
        secs = t % 60
        timer = '{:02d}:{:02d}'.format(mins, secs)
        print(timer, end="\r")  # overwrite previous line
        time.sleep(1)
        t -= 1
    print('Blast Off!!!')


t = input("Enter the time in seconds: ")

countdown(int(t))


def pomodoro():

    print("The Escape Room starts now. Find the 4 digits of the pincode. Write the digits in order from lowest to highest. You only have 3 tries")
    timer_start = datetime.now()
    secret_code = "3389"
    allotted_time = timedelta(seconds=6*60)
    error = 0
    while True:
        print("Enter the 4 digit pincode here:")
        code = input()
        now = datetime.now()
        time_taken = now - timer_start
        if time_taken > allotted_time:
            print("You took too much time! You lose!")
            time.sleep(60)
            return
        if code == secret_code:
            print("You managed to stop the mutation and escaped! You won!")
            time.sleep(60)
            return
        print("That's not the right code!")
        error += 1
        if error == 3:
            print("You took too many tries! You lose!")
            time.sleep(60)
            return
        print(f"You only have {allotted_time - time_taken} time left!")

pomodoro()
I think that the best way is to implement a GUI so you can show the countdown live, by implementing also a thread that runs the countdown.
In this way you have the countdown running no matter the attempts. You can also implement difficult by lowering 10 secs for example at every attempt.