Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define your PIN
- local correctPIN = "1234"
- -- GUI Functions
- local function drawScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 1 | 2 | 3 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 4 | 5 | 6 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 7 | 8 | 9 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| C | 0 | E |")
- print("| | | |")
- print("+-----+-----+-----+")
- term.setCursorPos(1, 18)
- write("Enter PIN:")
- end
- -- Main PIN Entry Function
- local function enterPIN()
- local enteredPIN = ""
- local attempts = 3
- while attempts > 0 do
- drawScreen()
- term.setCursorBlink(false)
- term.setCursorPos(12, 18)
- write(string.rep("*", #enteredPIN))
- local _, key = os.pullEvent("key")
- local number = tonumber(string.char(key))
- if number and number >= 0 and number <= 9 then
- enteredPIN = enteredPIN .. tostring(number)
- elseif key == keys.backspace then
- enteredPIN = string.sub(enteredPIN, 1, -2)
- elseif key == keys.enter then
- if enteredPIN == correctPIN then
- term.clear()
- term.setCursorPos(1, 1)
- print("Access Granted!")
- -- Perform actions upon successful entry
- break
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Incorrect PIN. Try again.")
- attempts = attempts - 1
- if attempts == 0 then
- print("Access Denied!")
- else
- print("Attempts remaining: " .. attempts)
- end
- sleep(2)
- enteredPIN = ""
- end
- end
- end
- end
- -- Start PIN Entry
- enterPIN()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement