Advertisement
Darking560

DigitCode API

Jul 29th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. --  Digit-Code API
  2.  
  3. function colors(mon,color)
  4.     if mon.isColor() then
  5.         mon.setBackgroundColor(color)
  6.     end
  7. end
  8.  
  9. function screen(mon)
  10.     colors(mon,0x8000)
  11.     mon.clear()
  12.     colors(mon,0x80)
  13.    
  14.     local count = 1
  15.     for i=2,4 do
  16.         for j=2,6,2 do
  17.             mon.setCursorPos(j,i)
  18.             mon.write(tostring(count))
  19.             count = count + 1
  20.         end
  21.     end
  22.     colors(mon,0x4000)
  23.     mon.setCursorPos(2,5)
  24.     mon.write("C")
  25.     colors(mon,0x20)
  26.     mon.setCursorPos(6,5)
  27.     mon.write("A")
  28. end
  29.  
  30. function start(mon)
  31.     local code = ""
  32.     local hide = ""
  33.     local valider = false
  34.    
  35.     screen(mon)
  36.    
  37.     while not valider do
  38.         local e, side, x, y = os.pullEvent("monitor_touch")
  39.        
  40.         if x == 2 and y == 2 then
  41.             code = code .. "1"
  42.             hide = hide .."*"
  43.         elseif x == 4 and y == 2 then
  44.             code = code .. "2"
  45.             hide = hide .."*"
  46.         elseif x == 6 and y == 2 then
  47.             code = code .. "3"
  48.             hide = hide .."*"
  49.         elseif x == 2 and y == 3 then
  50.             code = code .. "4"
  51.             hide = hide .."*"
  52.         elseif x == 4 and y == 3 then
  53.             code = code .. "5"
  54.             hide = hide .."*"
  55.         elseif x == 6 and y == 3 then
  56.             code = code .. "6"
  57.             hide = hide .."*"
  58.         elseif x == 2 and y == 4 then
  59.             code = code .. "7"
  60.             hide = hide .."*"
  61.         elseif x == 4 and y == 4 then
  62.             code = code .. "8"
  63.             hide = hide .."*"
  64.         elseif x == 6 and y == 4 then
  65.             code = code .. "9"
  66.             hide = hide .."*"
  67.         elseif x == 2 and y == 5 then
  68.             code = ""
  69.             hide = ""
  70.         elseif x == 6 and y == 5 then
  71.             valider = true
  72.         end
  73.        
  74.         if string.len(code) == 6 then
  75.             code = string.sub(code,5,6)
  76.             hide = "*"
  77.         end
  78.        
  79.         mon.setCursorPos(2,1)
  80.         colors(mon,0x8000)
  81.         mon.clearLine()
  82.         mon.write(hide)
  83.        
  84.     end
  85.     return code
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement