lord_thekenny

DigiCode

Mar 22nd, 2020 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. monit = peripheral.wrap("top")
  2. monit.setTextScale(0.5)
  3. x, y = monit.getSize()
  4.  
  5. -- PassWord --
  6. PassWord="1994"
  7.  
  8. PassWordTemp=""
  9.  
  10. -- Matris Pad DE MERDE CAR LES ECRAN SONT MAL FOUTU --
  11. MatrisPad = {
  12.   {"7","8","8",' ',"9"},
  13.   {"4","5","5",' ',"6"},
  14.   {' ',' ',' ',' ',' '},
  15.   {"1","2","2",' ',"3"},
  16.   {"1","2","2",' ',"3"},
  17.   {' ',"0","0",' ',' '},
  18.   {' ',"0","0",' ',' '}
  19. }
  20. -- Collection de Coord Pad --
  21. Coords_Pad = {
  22.   ["0"] = { ["x"]=8,["y"]=10},
  23.   ["1"] = { ["x"]=6,["y"]=8},
  24.   ["2"] = { ["x"]=8,["y"]=8},
  25.   ["3"] = { ["x"]=10,["y"]=8},
  26.   ["4"] = { ["x"]=6,["y"]=6},
  27.   ["5"] = { ["x"]=8,["y"]=6},
  28.   ["6"] = { ["x"]=10,["y"]=6},
  29.   ["7"] = { ["x"]=6,["y"]=4},
  30.   ["8"] = { ["x"]=8,["y"]=4},
  31.   ["9"] = { ["x"]=10,["y"]=4}
  32. }
  33.  
  34. Coords_In = {
  35.  {["x"]=5,["y"]=2},
  36.  {["x"]=7,["y"]=2},
  37.  {["x"]=9,["y"]=2},
  38.  {["x"]=11,["y"]=2}
  39. }
  40.  
  41. -- RAZ Monitor --
  42. function RAZ_Monitor(colorOver)
  43.   PassWordTemp = ""
  44.  
  45.   if colorOver ~= nil then
  46.     monit.setBackgroundColor(colorOver)
  47.   else
  48.     monit.setBackgroundColor(colors.lightGray)  
  49.   end
  50.   monit.clear()
  51. end
  52.  
  53. -- Error --
  54. function ErrorPass()
  55.   for i=0,5 do
  56.     RAZ_Monitor(colors.red)
  57.     sleep(0.5)
  58.     RAZ_Monitor()
  59.   end
  60.   Show_Pad()
  61. end
  62.  
  63. -- Affiche le pad numerique --
  64. function Show_Pad()
  65.   RAZ_Monitor()
  66.   count = 9
  67.   monit.setTextColor(colors.black)
  68.   for i=3,9 do
  69.     for j=11,5,-1 do
  70.       if j%2 == 0 and i%2 == 0 then
  71.         monit.setBackgroundColor(colors.lightGray)
  72.         monit.setCursorPos(j,i)
  73.         monit.write(""..count)
  74.         count = count - 1
  75.       else
  76.         monit.setBackgroundColor(colors.white)
  77.         monit.setCursorPos(j,i)
  78.         monit.write(' ')
  79.       end
  80.     end
  81.   end
  82.   -- first ligne --
  83.   monit.setCursorPos(5,2)
  84.   for i=5,11 do
  85.     if i%2 == 0 then
  86.       monit.setBackgroundColor(colors.lightGray)
  87.     else
  88.       monit.setBackgroundColor(colors.black)
  89.     end
  90.     monit.write(' ')
  91.   end
  92.  
  93.   -- last ligne --
  94.   monit.setCursorPos(2,10)
  95.   monit.setBackgroundColor(colors.red)
  96.   monit.write(' c ')
  97.   monit.setBackgroundColor(colors.white)
  98.   monit.write('   ')
  99.   monit.setBackgroundColor(colors.lightGray)
  100.   monit.write('0')
  101.   monit.setBackgroundColor(colors.white)
  102.   monit.write('   ')
  103.   monit.setCursorPos(12,10)
  104.   monit.setBackgroundColor(colors.green)
  105.   monit.write(' v ')
  106.  
  107.   monit.setBackgroundColor(colors.lightGray)  
  108. end
  109.  
  110. -- Input Sur le Clavier --
  111. function Saisie(num)
  112.   if num ~= ' ' then
  113.     -- Illumine la touche
  114.     local coordT = Coords_Pad[num]
  115.     monit.setBackgroundColor(colors.black)
  116.     monit.setCursorPos(coordT["x"],coordT["y"])
  117.     monit.write("0")
  118.     sleep(0.05)
  119.     monit.setBackgroundColor(colors.lightGray)
  120.     monit.setCursorPos(coordT["x"],coordT["y"])
  121.     monit.write(num)
  122.  
  123.     -- Add Pass
  124.     if #PassWordTemp <4 then
  125.       local coordI = Coords_In[#PassWordTemp+1]
  126.       monit.setBackgroundColor(colors.black)
  127.       monit.setCursorPos(coordI["x"],coordI["y"])
  128.       monit.setTextColor(colors.white)
  129.       monit.write("x")
  130.       PassWordTemp = PassWordTemp..num
  131.     end
  132.     DefaultColor()
  133.   end
  134. end
  135. -- Set Color --
  136. function DefaultColor()
  137.   monit.setBackgroundColor(colors.lightGray)
  138.   monit.setTextColor(colors.black)
  139. end
  140.  
  141. -- Validation --
  142. function Validation()
  143.   if PassWord == PassWordTemp then
  144.     rs.setOutput("right",true)
  145.     sleep(1)
  146.     rs.setOutput("right",false)
  147.     Show_Pad()
  148.   else
  149.     ErrorPass()            
  150.   end
  151. end
  152.  
  153. -- init --
  154. Show_Pad()
  155.  
  156. -- Boucle du program --
  157. while true do
  158.   event, side, xPos, yPos = os.pullEvent("monitor_touch")
  159.  
  160.   --monit.setCursorPos(1,1)
  161.   --monit.write(xPos..' '..yPos..' ')
  162.  
  163.   -- Pad Numerique
  164.   if (yPos<=10 and yPos >=5) and (xPos >=6 and xPos <= 11) then
  165.     Saisie(MatrisPad[yPos-4][xPos-6])
  166.   elseif yPos >=10 and (xPos >=3 and xPos <=5) then -- Cancel
  167.     Show_Pad()
  168.   elseif yPos >=10 and (xPos >=12 and xPos<=15) then -- Valider
  169.     Validation()  
  170.   end
  171.    
  172. end
Add Comment
Please, Sign In to add comment