Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIY Escape Room for fun
#1
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()
buran write Feb-16-2021, 06:04 PM:
my understanding is you have a question, so I deleted the other thread - in Code Share section of the forum.
please, don't start new threads unnecessarily
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Escape Single quotation between each content tag usman 3 433 May-02-2021, 03:32 PM
Last Post: snippsat
  How to escape OrderedDict as an argument? Mark17 2 477 Dec-23-2020, 06:47 PM
Last Post: Mark17
  help for escape sequences NewPi 1 755 Dec-11-2019, 11:22 PM
Last Post: ichabod801
  escape single quote deep_logic 1 723 Sep-10-2019, 08:05 PM
Last Post: SheeppOSU
  The use of escape char \ hishamzero1 2 978 Aug-12-2019, 10:20 PM
Last Post: hishamzero1
  Escape sequences display in python Uchikago 1 876 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  Python 3 escape codes oldDog 1 1,244 Sep-15-2018, 10:12 AM
Last Post: gruntfutuk
  Meeting Room Booking r7rajkumar 0 1,355 Jul-17-2018, 10:11 AM
Last Post: r7rajkumar
  OSX: copied path has escape character ronjan 4 1,811 Mar-14-2018, 06:23 PM
Last Post: ronjan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020