Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Start of the game
- # Have the user set a code that is 4-6 numbers
- # Check to make sure it is 4-6 numbers and pass the
- # code to the next part of the setup
- def startgame():
- dcl = input("Set the disarm code (4-6 chars): ")
- if len(dcl) < 3 or len(dcl) > 5:
- print("You must enter a number that is 4 to 6 char.")
- startgame()
- else:
- dc = int(dcl)
- setupswitches(dc)
- # Wait for the user to set the switch positions
- # then read the postitions of the switches and
- # convert it to a binary format
- # Then pass it along to the next step
- def setupswitches(dc):
- sw1 = (input("Switch 1: 0/1: "))
- sw2 = (input("Switch 2: 0/1: "))
- sw3 = (input("Switch 3: 0/1: "))
- sw4 = (input("Switch 4: 0/1: "))
- swstr = (sw1 + sw2 + sw3 + sw4)
- swbinary = int(swstr)
- setuptimer(swbinary, dc)
- # Wait for user to select the time
- # Check to make sure the time is between 1-9999
- # pass the info to the next setup
- def setuptimer(swbinary, dc):
- swbinary = swbinary
- dc = dc
- cdt = input("Enter countdown time: ie:0-9999: ")
- if len(cdt) < 1 or len(cdt) > 5:
- print("Follow directions. Now start over")
- startgame()
- else:
- countdown = int(cdt)
- waitforready(swbinary, dc, countdown)
- # Everything is setup
- # Wait for user to make the device ready
- def waitforready(swbinary, dc, countdown):
- swbinary = swbinary
- dc = dc
- countdown = countdown
- swstart = int(input("Input 0 for ready: "))
- if swstart == 0:
- waitforstart(swbinary, dc, countdown)
- if swstart == 1:
- waitforready(swbinary, dc, countdown)
- # Wait for device to become active
- def waitforstart(swbinary, dc, countdown):
- swbinary = swbinary
- dc = dc
- countdown = countdown
- swstart = int(input("Input 0 to start: "))
- if swstart == 0:
- playgame(swbinary, dc, countdown)
- if swstart == 1:
- waitforstart(swbinary, dc, countdown)
- # Start the game
- # We wait for the switches to be in the proper
- # place before we allow a code to be entered
- # 3 attempts at the code is all that is allowed
- #todo Add the timer function in
- def playgame(swbinary, dc, countdown):
- swcode = swbinary
- print(swcode)
- dac = dc
- badcode = 0
- usc = int(input("Enter the switch code: "))
- if usc == swcode:
- while True:
- uec = int(input("Enter the disarm code: Limited attempts: "))
- if badcode > 1:
- print("You Loose")
- playmore()
- if badcode <= 2 and dac == uec:
- print("Disarmed")
- playmore()
- if badcode <= 2 and dac != uec:
- print("WRONG CODE - Time is running out!")
- badcode = badcode + 1
- else:
- playgame(swbinary, dc)
- def playmore():
- playanotherraw = input("Play again? Y/N: ")
- playanother = playanotherraw.upper()
- if playanother == "Y":
- startgame()
- if playanother == "N":
- exit()
- else:
- print("You stupid!")
- exit()
- startgame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement