Nike622000

PW TÜR

Jul 25th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. --Monitor/Sensor
  3. monSide = "back"
  4. senSide = "top"
  5. --Tastenfeld
  6. Bcolor = colors.gray
  7. Tcolor = colors.lightGray
  8. --Hintergrund
  9. Bcol = colors.black
  10. --RS-Seiten
  11. tuer = "bottom"
  12. falsch = "left"
  13.  
  14.  
  15. mon = peripheral.wrap(monSide)
  16. proximity = sensor.wrap(senSide)
  17. xMax,yMax = mon.getSize()
  18.  
  19.  
  20. --background
  21. function bdraw()
  22. for yPos = 1,yMax do
  23. for xPos = 1,xMax do
  24. mon.setCursorPos(xPos,yPos)
  25. mon.setBackgroundColor(Bcol)
  26. mon.write(" ")
  27. end
  28. end
  29. end
  30.  
  31. --layout
  32. function layout()
  33.  
  34. mon.setBackgroundColor(Bcolor)
  35. mon.setTextColor(Tcolor)
  36.  
  37. mon.setCursorPos(2,1)
  38. mon.write("1")
  39.  
  40. mon.setCursorPos(4,1)
  41. mon.write("2")
  42.  
  43. mon.setCursorPos(6,1)
  44. mon.write("3")
  45.  
  46. mon.setCursorPos(2,3)
  47. mon.write("4")
  48.  
  49. mon.setCursorPos(4,3)
  50. mon.write("5")
  51.  
  52. mon.setCursorPos(6,3)
  53. mon.write("6")
  54.  
  55. mon.setCursorPos(2,5)
  56. mon.write("7")
  57.  
  58. mon.setCursorPos(4,5)
  59. mon.write("8")
  60.  
  61. mon.setCursorPos(6,5)
  62. mon.write("9")
  63.  
  64. mon.setCursorPos(8,1)
  65. mon.setBackgroundColor(colors.cyan)
  66. mon.write("R ")
  67.  
  68. mon.setCursorPos(8,3)
  69. mon.setBackgroundColor(colors.red)
  70. mon.write("C ")
  71.  
  72. mon.setCursorPos(8,5)
  73. mon.setBackgroundColor(colors.green)
  74. mon.write("OK")
  75.  
  76. end
  77.  
  78. --
  79. i=1
  80. --main program
  81. bdraw()
  82. layout()
  83. rs.setOutput(tuer, false)
  84. rs.setOutput(falsch, false)
  85. while true do
  86. stelle = 0
  87. password = nil
  88. mon.setBackgroundColor(colors.black)
  89. mon.setCursorPos(10,1)
  90. mon.write("                       ")
  91. --Spieler erkennung
  92. targets = proximity.getTargets()
  93.   for k,v in pairs(targets) do
  94.   if v.Name == "Player"
  95.   and v.Position.X <= 1 and v.Position.X >= -1
  96.   and v.Position.Y <= 0 and v.Position.Y >= -4
  97.   and v.Position.Z <= 4 and v.Position.Z >= 1.5 then
  98.   player = k
  99.   mon.setBackgroundColor(Bcolor)
  100.   mon.setCursorPos(10,1)
  101.   mon.write(player)
  102.    
  103.   file = fs.open("pw", "r")
  104.  
  105.   line = file.readLine()
  106.   count = 1
  107.   while line ~= nil do
  108.     pl = line
  109.     line = file.readLine()
  110.     pw = line
  111.     line = file.readLine()
  112.     count = count + 1
  113.    
  114.     if player == pl then
  115.     password = pw
  116.     end
  117.   end
  118.   if password == nil then
  119.   print("Spieler nicht erkannt")
  120.   rs.setOutput(falsch, true)
  121.   sleep(3)
  122.   rs.setOutput(falsch, false)
  123.   end
  124.   file.close()
  125.   eingabe = true
  126.   Kennwort = {}
  127.  while eingabe do
  128.   event,_,xPos,yPos = os.pullEvent("monitor_touch")
  129.   b = nil
  130.   if xPos == 2 and yPos == 1 then
  131.   print("1")
  132.   b = 1
  133.   elseif xPos == 4 and yPos == 1 then
  134.   print("2")
  135.   b = 2
  136.   elseif xPos == 6 and yPos == 1 then
  137.   print("3")
  138.   b = 3
  139.   elseif xPos == 2 and yPos == 3 then
  140.   print("4")
  141.   b = 4
  142.   elseif xPos == 4 and yPos == 3 then
  143.   print("5")
  144.   b = 5
  145.   elseif xPos == 6 and yPos == 3 then
  146.   print("6")
  147.   b = 6
  148.   elseif xPos == 2 and yPos == 5 then
  149.   print("7")
  150.   b = 7
  151.   elseif xPos == 4 and yPos == 5 then
  152.   print("8")
  153.   b = 8
  154.   elseif xPos == 6 and yPos == 5 then
  155.   print("9")
  156.   b = 9
  157.   elseif xPos >= 8 and xPos <=9 and yPos == 1 then
  158.   print("R")
  159.   os.reboot()
  160.   elseif xPos >= 8 and xPos <=9 and yPos == 3 then
  161.   print("C")
  162.   b =  -1
  163.   stelle = stelle-2
  164.   elseif xPos >= 8 and xPos <=9 and yPos == 5 then
  165.   print("OK")
  166.   b = 0
  167.   end
  168.   if b ~= nil then
  169.     stelle = stelle+1
  170.   end
  171.  
  172.   if stelle == -1 then
  173.   stelle = 0
  174.   end
  175.  
  176.   if stelle > 4 then
  177.   stelle = 4
  178.   end
  179.  
  180.   if b==0 then
  181.   for g = 1,4 do
  182.   if Kennwort[g] == nil then
  183.   bdraw()
  184.   mon.setCursorPos(1,1)
  185.   mon.setTextColor(colors.red)
  186.   mon.write("mindestens 4")
  187.   mon.setCursorPos(1,2)
  188.   mon.write("Zahlen eingeben!")
  189.   sleep(3)
  190.   os.reboot()
  191.   end
  192.   end
  193.   Kwkomplett = Kennwort[1] .. Kennwort[2] .. Kennwort[3] .. Kennwort[4]
  194.   if Kwkomplett == password then
  195.   bdraw()
  196.   mon.setCursorPos(1,1)
  197.   mon.setTextColor(colors.green)
  198.   mon.write("Passwort")
  199.   mon.setCursorPos(1,2)
  200.   mon.write("akzeptiert")
  201.   rs.setOutput(tuer, true)
  202.   sleep(5)
  203.   rs.setOutput(tuer, false)
  204.   os.reboot()
  205.   else
  206.   bdraw()
  207.   mon.setCursorPos(1,1)
  208.   mon.setTextColor(colors.red)
  209.   mon.write("Falsches Passwort")
  210.   rs.setOutput(falsch, true)
  211.   sleep(3)
  212.   rs.setOutput(falsch, false)
  213.   os.reboot()
  214.   end
  215.   elseif b==-1 then
  216.     if stelle > 0 then
  217.       Kennwort[stelle+1] = nil
  218.       end
  219.   else
  220.     Kennwort[stelle] = b
  221.   end
  222.  
  223.   mon.setCursorPos(10,3)
  224.   mon.setBackgroundColor(Bcol)
  225.   mon.write("     ")
  226.   for stern = 1,stelle do
  227.   mon.setCursorPos(10+stern,3)
  228.   mon.setBackgroundColor(Bcolor)
  229.   mon.write("*")
  230.   end
  231.  
  232.  
  233.  end
  234.  
  235.    
  236.   end
  237.   end
  238.  
  239.   mon.setBackgroundColor(Bcol)
  240.   mon.setTextColor(Tcolor)
  241.  
  242.  
  243.   if i == 1 then
  244.   mon.setCursorPos(11,1)
  245.   mon.write("Ooo")
  246.   elseif i == 2 then
  247.   mon.setCursorPos(11,1)
  248.   mon.write("oOo")
  249.   elseif i == 3 then
  250.   mon.setCursorPos(11,1)
  251.   mon.write("ooO")
  252.   elseif i == 4 then
  253.   mon.setCursorPos(11,1)
  254.   mon.write("ooo")
  255.   i=0
  256.   end
  257.   i=i+1
  258.   sleep(0.5)
  259.  
  260. end
Advertisement
Add Comment
Please, Sign In to add comment