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


Messages In This Thread
DIY Escape Room for fun - by StannemanPython - Feb-16-2021, 05:04 PM
RE: DIY Escape Room for fun - by maurom82 - Feb-17-2021, 10:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  use of escape character in re.sub and find WJSwan 1 910 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  Escape indentation Frankduc 11 3,079 Jan-31-2022, 02:41 PM
Last Post: Frankduc
  add Escape charcters in string GrahamL 3 1,174 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  Meeting Room Booking r7rajkumar 1 3,834 Sep-29-2021, 10:44 AM
Last Post: jefsummers
  Escape Single quotation between each content tag usman 3 2,807 May-02-2021, 03:32 PM
Last Post: snippsat
  How to escape OrderedDict as an argument? Mark17 2 2,027 Dec-23-2020, 06:47 PM
Last Post: Mark17
  help for escape sequences NewPi 1 2,033 Dec-11-2019, 11:22 PM
Last Post: ichabod801
  escape single quote deep_logic 1 1,804 Sep-10-2019, 08:05 PM
Last Post: SheeppOSU
  The use of escape char \ hishamzero1 2 2,379 Aug-12-2019, 10:20 PM
Last Post: hishamzero1
  Escape sequences display in python Uchikago 1 2,431 Jun-27-2019, 03:25 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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