Advertisement
Guest User

keypad

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2.  
  3. mon.setBackgroundColor(colors.blue)
  4. mon.clear()
  5.  
  6. local function keypad(x, y)
  7.   x = x or 3
  8.   y = y or 2
  9.   mon.setTextColor(colors.black)
  10.   mon.setBackgroundColor(colors.lightGray)
  11.   mon.setCursorPos(x, y)
  12.   mon.write("123")
  13.   mon.setCursorPos(x, y+1)
  14.   mon.write("456")
  15.   mon.setCursorPos(x, y+2)
  16.   mon.write("789")
  17.   mon.setTextColor(colors.red)
  18.   mon.setCursorPos(x, y+3)
  19.   mon.write("<")
  20.   mon.setTextColor(colors.black)
  21.   mon.write("0")
  22.   mon.setTextColor(colors.lime)
  23.   mon.write("/")
  24. end
  25.  
  26. local function digits(dT)
  27.   mon.setTextColor(colors.white)
  28.   mon.setBackgroundColor(colors.black)
  29.   mon.setCursorPos(2, 1)
  30.   mon.write(dT..string.rep(" ", 5-#dT))
  31. end
  32.  
  33. local digitsTyped = ""
  34.  
  35. local pad = {
  36.   {1, 2, 3},
  37.   {4, 5, 6},
  38.   {7, 8, 9},
  39.   {"<", 0, "/"}
  40. }
  41.  
  42. local function verify()
  43.   if digitsTyped == "12345" then
  44.     loop = acc
  45.     print("HELLO")
  46.   else
  47.     mon.setCursorPos(2, 1)
  48.     mon.setTextColor(colors.red)
  49.     print(digitsTyped)
  50.     mon.write("WRONG")
  51.     sleep(4)
  52.     digitsTyped = ""
  53.   end
  54. end
  55.  
  56. local function touch(x, y)
  57.   local _x = 3 -- to 5
  58.   local _y = 2 -- to 5
  59.  
  60.   if x < _x or x > 5 or y < _y or y > 5 then
  61.     return
  62.   end
  63.    
  64.   local d = pad[y-1][x-2]
  65.   if d == "<" then
  66.     digitsTyped = digitsTyped:sub(1, -2)
  67.   elseif d == "/" then
  68.     verify()
  69.   else
  70.     if #digitsTyped < 5 then
  71.       digitsTyped = digitsTyped..d
  72.     end
  73.   end
  74. end
  75.  
  76. keypad()
  77. local function login()
  78.   digits(digitsTyped)
  79.   local e, p1, p2, p3, p4 = os.pullEvent()
  80.   if e == "monitor_touch" and p1 == "top" then
  81.     touch(p2, p3)
  82.   end
  83. end
  84.  
  85. local function acc()
  86.   mon.setBackgroundColor(colors.black)
  87.   mon.setTextColor(colors.lime)
  88.   mon.clear()
  89.   mon.setCursorPos(2, 2)
  90.   mon.write("VERIFIED")
  91. end
  92.  
  93. local loop = login
  94.  
  95. while true do
  96.   loop()
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement