Advertisement
Plazter

TouchPad Password door

Apr 3rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. component = require("component")
  2. term      = require("term")
  3. event     = require("event")
  4. rs        = component.redstone
  5. colors    = require("colors")
  6. gpu       = component.gpu
  7. sides     = require("sides")
  8.  
  9. args = {...}
  10. posX = 3
  11.  
  12. pressedPass = {}
  13.  
  14. gui = {
  15.         [1] =  "|-----------|",
  16.         [2] =  "|           |",
  17.         [3] =  "|-----------|",
  18.         [4] =  "| 1 | 2 | 3 |",
  19.         [5] =  "|-----------|",
  20.         [6] =  "| 4 | 5 | 6 |",
  21.         [7] =  "|-----------|",
  22.         [8] =  "| 7 | 8 | 9 |",
  23.         [9] =  "|-----------|",
  24.         [10] = "|[x]| 0 |[v]|",
  25.         [11] = "|-----------|",
  26.         [12] =  "  "
  27. }
  28.  
  29. pass = {
  30.           [1] = "1",
  31.           [2] = "2",
  32.           [3] = "3",
  33.           [4] = "4",
  34.       }
  35.  
  36. function checkPass()
  37.     if pressedPass[1] == pass[1] and pressedPass[2] == pass[2] and pressedPass[3] == pass[3] and pressedPass[4] == pass[4] then
  38.         rs.setBundledOutput(sides.west, colors.red, 15)
  39.         os.sleep(3)
  40.         rs.setBundledOutput(sides.west, colors.red, 0)
  41.         gpu.set(2,2,"           ")
  42.         else
  43.         pressedPass = nil
  44.         pressedPass = {}
  45.         gpu.set(2,2,"           ")
  46.   end
  47. end
  48.  
  49. function debug()
  50.   if args[1] == "debug" then
  51.   term.setCursor(1,14)
  52.   for k,v in pairs(pressedPass) do
  53.     print(v)
  54.   end
  55.   end
  56. end
  57.  
  58. function draw()
  59.   for k,v in pairs(gui) do
  60.     gpu.set(1,k, v)
  61.   end
  62. end
  63.  
  64. function checkX()
  65.   posX = posX + 2
  66.   if posX >= 12 then
  67.     gpu.set(2,2, "           ")
  68.     posX = 3
  69.     pressedPass = nil
  70.     pressedPass = {}
  71.   end
  72. end
  73. gpu.setResolution(14,14)
  74. draw()
  75.  
  76. while true do
  77.   _,_, x, y = event.pull(0.1, "touch")
  78.  
  79.     if x >= 2 and x <= 4 and y == 4 then -- 1
  80.       gpu.set(posX, 2, "*")
  81.       table.insert(pressedPass, "1")
  82.       debug()
  83.       checkX()
  84.     elseif x >= 6 and x <= 8 and y == 4 then -- 2
  85.       gpu.set(posX, 2, "*")
  86.       table.insert(pressedPass, "2")
  87.       debug()
  88.       checkX()
  89.     elseif x >= 10 and x <= 12 and y == 4 then -- 3
  90.       gpu.set(posX, 2, "*")
  91.       table.insert(pressedPass, "3")
  92.       debug()
  93.       checkX()
  94.     elseif x >= 2 and x <= 4 and y == 6 then -- 4
  95.       gpu.set(posX, 2, "*")
  96.       table.insert(pressedPass, "4")
  97.       debug()
  98.       checkX()
  99.     elseif x >= 6 and x <= 8 and y == 6 then -- 5
  100.       gpu.set(posX, 2, "*")
  101.       table.insert(pressedPass, "5")
  102.       debug()
  103.       checkX()
  104.     elseif x >= 10 and x <= 12 and y == 6 then -- 6
  105.       gpu.set(posX, 2, "*")
  106.       table.insert(pressedPass, "6")
  107.       debug()
  108.       checkX()  
  109.     elseif x >= 2 and x <= 4 and y == 8 then -- 7
  110.       gpu.set(posX, 2, "*")
  111.       table.insert(pressedPass, "7")
  112.       debug()
  113.       checkX()
  114.     elseif x >= 6 and x <= 8 and y == 8 then -- 8
  115.       gpu.set(posX, 2, "*")
  116.       table.insert(pressedPass, "8")
  117.       debug()
  118.       checkX()  
  119.     elseif x >= 10 and x <= 12 and y == 8 then -- 9
  120.       gpu.set(posX, 2, "*")
  121.       table.insert(pressedPass, "9")
  122.       debug()
  123.       checkX()
  124.     elseif x >= 2 and x <= 4 and y == 10 then -- cancel
  125.       gpu.set(2,2, "        ")
  126.       posX = 3
  127.       pressedPass = nil
  128.       pressedPass = {}
  129.     elseif x >= 6 and x <= 8 and y == 10 then --0
  130.         gpu.set(posX, 2, "*")
  131.         table.insert(pressedPass, "0")
  132.         checkX()
  133.     elseif x >= 10 and x <= 12 and y == 10 then
  134.       checkPass()
  135.     elseif x >= 2 and x <= 5 and y == 12 then
  136.       gpu.setResolution(100,50)
  137.       term.clear()
  138.       break
  139.     end
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement