Advertisement
EmptySet5150

Escape room game Switches and Code V0.2

Dec 24th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.31 KB | None | 0 0
  1. from threading import Thread
  2. from time import sleep
  3. import os, sys
  4.  
  5. # Start of the game
  6. # Have the user set a code that is 4-6 numbers
  7. # Check to make sure it is 4-6 numbers and pass the
  8. # code to the next part of the setup
  9. # todo Letters fail the program
  10. def setupgame():
  11.     dcl = input("Set the disarm code (4-6 chars): ")
  12.     if len(dcl) < 4 or len(dcl) > 6:
  13.         print("You must enter a number that is 4 to 6 char.")
  14.         setupgame()
  15.     else:
  16.         dc = int(dcl)
  17.         setupswitches(dc)
  18.  
  19.  
  20. # Wait for the user to set the switch positions
  21. # then read the postitions of the switches and
  22. # convert it to a binary format
  23. # Then pass it along to the next step
  24. def setupswitches(dc):
  25.     print("This will be read from inputs:")
  26.     sw1 = (input("Switch 1: 0/1: "))
  27.     sw2 = (input("Switch 2: 0/1: "))
  28.     sw3 = (input("Switch 3: 0/1: "))
  29.     sw4 = (input("Switch 4: 0/1: "))
  30.     swstr = (sw1 + sw2 + sw3 + sw4)
  31.     swbinary = int(swstr)
  32.     setuptimer(swbinary, dc)
  33.  
  34.  
  35. # Wait for user to select the time
  36. # Check to make sure the time is between 100-9999
  37. # pass the info to the next setup
  38. # todo Letters also fail here
  39. def setuptimer(swbinary, dc):
  40.     swbinary = swbinary
  41.     dc = dc
  42.     cdt = input("Enter countdown time (100-9999): ")
  43.     if len(cdt) < 3 or len(cdt) > 4:
  44.         print("Follow directions")
  45.         setuptimer(swbinary, dc)
  46.     else:
  47.         countdown = int(cdt)
  48.         waitforready(swbinary, dc, countdown)
  49.  
  50.  
  51. # Everything is setup
  52. # Wait for user to make the device ready
  53. def waitforready(swbinary, dc, countdown):
  54.     swbinary = swbinary
  55.     dc = dc
  56.     countdown = countdown
  57.     print("This is when the case is closed")
  58.     swstart = int(input("Input 0 for ready: "))
  59.     if swstart == 0:
  60.         waitforstart(swbinary, dc, countdown)
  61.     if swstart == 1:
  62.         waitforready(swbinary, dc, countdown)
  63.  
  64.  
  65. # Start the countdown timer
  66. # todo This should be interatbale and displayed on a single line while the code can be entered
  67. def starttimer(cdt):
  68.     tisup = cdt
  69.     while tisup > 1:
  70.         print(tisup)
  71.         sleep(1)
  72.         tisup = tisup - 1
  73.         if tisup == 0:
  74.             gameover()
  75.  
  76.  
  77. # This is a timer for when the shock sensor is true
  78. def fasttimer(cdt):
  79.     ftisup = cdt
  80.     while ftisup > 1:
  81.         print(ftisup)
  82.         sleep(.5)
  83.         ftisup = ftisup - 1
  84.         if ftisup == 0:
  85.             gameover()
  86.  
  87.  
  88. # Shock sensor speeds up timer
  89. def shock():
  90.     # todo If shock is true then start a faster timer
  91.     # todo get current time from start timer and send it to fasttimer
  92.     endgame()
  93.  
  94.  
  95. # Start the game process
  96. def startgame(swbinary, dc):
  97.     swcode = swbinary
  98.     dac = dc
  99.     badcode = 0
  100.     print("This will be read from the inputs")
  101.     usc = int(input("Enter the switch code: "))
  102.     if usc == swcode:
  103.         while True:
  104.             uec = int(input("Enter the disarm code: Limited attempts: "))
  105.             if badcode > 1:
  106.                 print("You Loose")
  107.                 gameover()
  108.             if badcode <= 2 and dac == uec:
  109.                 print("Disarmed")
  110.                 playmore()
  111.             if badcode <= 2 and dac != uec:
  112.                 print("WRONG CODE - Time is running out!")
  113.                 badcode = badcode + 1
  114.     else:
  115.         startgame(swbinary, dc)
  116.  
  117.  
  118. # Wait for device to become active
  119. def waitforstart(swbinary, dc, countdown):
  120.     swbinary = swbinary
  121.     dc = dc
  122.     countdown = countdown
  123.     print("This is when case is reopened")
  124.     swstart = int(input("Input 0 to start: "))
  125.     # When device is active
  126.     # Timer starts
  127.     # Switches must be in the position to enter code
  128.     # 3 Attempts at the code
  129.     # todo This does not work correctly
  130.     if swstart == 0:
  131.         start1 = Thread(target=starttimer(countdown))
  132.         start2 = Thread(target=startgame(swbinary, dc))
  133.         start1.start()
  134.         start2.start()
  135.     if swstart == 1:
  136.         waitforstart(swbinary, dc, countdown)
  137.  
  138.  
  139. # End game
  140. def gameover():
  141.     print("You have failed")
  142.     playmore()
  143.  
  144.  
  145. # Play again
  146. def playmore():
  147.     playanotherraw = input("Play again? Y/N: ")
  148.     playanother = playanotherraw.upper()
  149.     if playanother == "Y":
  150.         setupgame()
  151.     if playanother == "N":
  152.         exit()
  153.     else:
  154.         print("That was not a option!")
  155.         exit()
  156.  
  157.  
  158. # Start
  159. setupgame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement