Advertisement
EmptySet5150

Escape room game Switches and Code

Dec 22nd, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. # Start of the game
  2. # Have the user set a code that is 4-6 numbers
  3. # Check to make sure it is 4-6 numbers and pass the
  4. # code to the next part of the setup
  5. def startgame():
  6.     dcl = input("Set the disarm code (4-6 chars): ")
  7.     if len(dcl) < 3 or len(dcl) > 5:
  8.         print("You must enter a number that is 4 to 6 char.")
  9.         startgame()
  10.     else:
  11.         dc = int(dcl)
  12.         setupswitches(dc)
  13.  
  14.  
  15. # Wait for the user to set the switch positions
  16. # then read the postitions of the switches and
  17. # convert it to a binary format
  18. # Then pass it along to the next step
  19. def setupswitches(dc):
  20.     sw1 = (input("Switch 1: 0/1: "))
  21.     sw2 = (input("Switch 2: 0/1: "))
  22.     sw3 = (input("Switch 3: 0/1: "))
  23.     sw4 = (input("Switch 4: 0/1: "))
  24.     swstr = (sw1 + sw2 + sw3 + sw4)
  25.     swbinary = int(swstr)
  26.     setuptimer(swbinary, dc)
  27.  
  28.  
  29. # Wait for user to select the time
  30. # Check to make sure the time is between 1-9999
  31. # pass the info to the next setup
  32. def setuptimer(swbinary, dc):
  33.     swbinary = swbinary
  34.     dc = dc
  35.     cdt = input("Enter countdown time: ie:0-9999: ")
  36.     if len(cdt) < 1 or len(cdt) > 5:
  37.         print("Follow directions. Now start over")
  38.         startgame()
  39.     else:
  40.         countdown = int(cdt)
  41.         waitforready(swbinary, dc, countdown)
  42.  
  43.  
  44. # Everything is setup
  45. # Wait for user to make the device ready
  46. def waitforready(swbinary, dc, countdown):
  47.     swbinary = swbinary
  48.     dc = dc
  49.     countdown = countdown
  50.     swstart = int(input("Input 0 for ready: "))
  51.     if swstart == 0:
  52.         waitforstart(swbinary, dc, countdown)
  53.     if swstart == 1:
  54.         waitforready(swbinary, dc, countdown)
  55.  
  56.  
  57. # Wait for device to become active
  58. def waitforstart(swbinary, dc, countdown):
  59.     swbinary = swbinary
  60.     dc = dc
  61.     countdown = countdown
  62.     swstart = int(input("Input 0 to start: "))
  63.     if swstart == 0:
  64.         playgame(swbinary, dc, countdown)
  65.     if swstart == 1:
  66.         waitforstart(swbinary, dc, countdown)
  67.  
  68.  
  69. # Start the game
  70. # We wait for the switches to be in the proper
  71. # place before we allow a code to be entered
  72. # 3 attempts at the code is all that is allowed
  73. #todo Add the timer function in
  74. def playgame(swbinary, dc, countdown):
  75.     swcode = swbinary
  76.     print(swcode)
  77.     dac = dc
  78.     badcode = 0
  79.     usc = int(input("Enter the switch code: "))
  80.     if usc == swcode:
  81.         while True:
  82.             uec = int(input("Enter the disarm code: Limited attempts: "))
  83.             if badcode > 1:
  84.                 print("You Loose")
  85.                 playmore()
  86.             if badcode <= 2 and dac == uec:
  87.                 print("Disarmed")
  88.                 playmore()
  89.             if badcode <= 2 and dac != uec:
  90.                 print("WRONG CODE - Time is running out!")
  91.                 badcode = badcode + 1
  92.     else:
  93.         playgame(swbinary, dc)
  94.  
  95.  
  96. def playmore():
  97.     playanotherraw = input("Play again? Y/N: ")
  98.     playanother = playanotherraw.upper()
  99.     if playanother == "Y":
  100.         startgame()
  101.     if playanother == "N":
  102.         exit()
  103.     else:
  104.         print("You stupid!")
  105.         exit()
  106.  
  107.  
  108. startgame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement