Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from threading import Thread
- from time import sleep
- import os, sys
- # 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
- # todo Letters fail the program
- def setupgame():
- dcl = input("Set the disarm code (4-6 chars): ")
- if len(dcl) < 4 or len(dcl) > 6:
- print("You must enter a number that is 4 to 6 char.")
- setupgame()
- 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):
- print("This will be read from inputs:")
- 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 100-9999
- # pass the info to the next setup
- # todo Letters also fail here
- def setuptimer(swbinary, dc):
- swbinary = swbinary
- dc = dc
- cdt = input("Enter countdown time (100-9999): ")
- if len(cdt) < 3 or len(cdt) > 4:
- print("Follow directions")
- setuptimer(swbinary, dc)
- 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
- print("This is when the case is closed")
- swstart = int(input("Input 0 for ready: "))
- if swstart == 0:
- waitforstart(swbinary, dc, countdown)
- if swstart == 1:
- waitforready(swbinary, dc, countdown)
- # Start the countdown timer
- # todo This should be interatbale and displayed on a single line while the code can be entered
- def starttimer(cdt):
- tisup = cdt
- while tisup > 1:
- print(tisup)
- sleep(1)
- tisup = tisup - 1
- if tisup == 0:
- gameover()
- # This is a timer for when the shock sensor is true
- def fasttimer(cdt):
- ftisup = cdt
- while ftisup > 1:
- print(ftisup)
- sleep(.5)
- ftisup = ftisup - 1
- if ftisup == 0:
- gameover()
- # Shock sensor speeds up timer
- def shock():
- # todo If shock is true then start a faster timer
- # todo get current time from start timer and send it to fasttimer
- endgame()
- # Start the game process
- def startgame(swbinary, dc):
- swcode = swbinary
- dac = dc
- badcode = 0
- print("This will be read from the inputs")
- 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")
- gameover()
- 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:
- startgame(swbinary, dc)
- # Wait for device to become active
- def waitforstart(swbinary, dc, countdown):
- swbinary = swbinary
- dc = dc
- countdown = countdown
- print("This is when case is reopened")
- swstart = int(input("Input 0 to start: "))
- # When device is active
- # Timer starts
- # Switches must be in the position to enter code
- # 3 Attempts at the code
- # todo This does not work correctly
- if swstart == 0:
- start1 = Thread(target=starttimer(countdown))
- start2 = Thread(target=startgame(swbinary, dc))
- start1.start()
- start2.start()
- if swstart == 1:
- waitforstart(swbinary, dc, countdown)
- # End game
- def gameover():
- print("You have failed")
- playmore()
- # Play again
- def playmore():
- playanotherraw = input("Play again? Y/N: ")
- playanother = playanotherraw.upper()
- if playanother == "Y":
- setupgame()
- if playanother == "N":
- exit()
- else:
- print("That was not a option!")
- exit()
- # Start
- setupgame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement