Advertisement
koki2000

gombos jelszó rendszer terminálra

Oct 31st, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. local pullEvent = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. w, h = term.getSize()
  5. run = true
  6. tempcolor = nil
  7. password = ""
  8.  
  9. local gomb = {}
  10. term.clear()
  11. gomb[1] = {x = 1, y = 3, x2 = 3, y2 = 3, color = colors.red, szoveg = "1"}
  12. gomb[2] = {x = 5, y = 3, x2 = 7, y2 = 3, color = colors.red, szoveg = "2"}
  13. gomb[3] = {x = 9, y = 3, x2 = 11, y2 = 3, color = colors.red, szoveg = "3"}
  14. gomb[4] = {x = 1, y = 5, x2 = 3, y2 = 5, color = colors.red, szoveg = "4"}
  15. gomb[5] = {x = 5, y = 5, x2 = 7, y2 = 5, color = colors.red, szoveg = "5"}
  16. gomb[6] = {x = 9, y = 5, x2 = 11, y2 = 5, color = colors.red, szoveg = "6"}
  17. gomb[7] = {x = 1, y = 7, x2 = 3, y2 = 7, color = colors.red, szoveg = "7"}
  18. gomb[8] = {x = 5, y = 7, x2 = 7, y2 = 7, color = colors.red, szoveg = "8"}
  19. gomb[9] = {x = 9, y = 7, x2 = 11, y2 = 7, color = colors.red, szoveg = "9"}
  20. gomb[10] = {x = 1, y = 9, x2 = 3, y2 = 9, color = colors.red, szoveg = "*"}
  21. gomb[11] = {x = 5, y = 9, x2 = 7, y2 = 9, color = colors.red, szoveg = "0"}
  22. gomb[12] = {x = 9, y = 9, x2 = 11, y2 = 9, color = colors.red, szoveg = "#"}
  23.  
  24.  
  25. function tclr()
  26.  term.clear()
  27.  term.setCursorPos(1,1)
  28. end
  29.  
  30. function kirajzol()
  31.  term.clear()
  32.  term.setTextColor(colors.yellow)
  33.  term.setBackgroundColor(colors.green)
  34.  for i = 1, 11 do
  35.   for j = 1, 1 do
  36.    term.setCursorPos(i, j)
  37.    term.write(" ")
  38.    hossz = string.len(password)
  39.    term.setCursorPos(12/2-(hossz/2)+1, 1)
  40.    term.write(password)
  41.   end
  42.  end
  43.  term.setTextColor(colors.white)
  44.  for i = 1, #gomb do
  45.   for j = 0 + gomb[i].y, gomb[i].y2 do
  46.    for k = 0 + gomb[i].x, gomb[i].x2 do
  47.     term.setCursorPos(k, j)
  48.     term.setBackgroundColor(gomb[i].color)
  49.     print(" ")
  50.    end
  51.   end
  52.   term.setCursorPos(gomb[i].x+1, gomb[i].y)
  53.   print(gomb[i].szoveg)
  54.  end
  55.  term.setBackgroundColor(colors.black)
  56. end
  57.  
  58. function paint()
  59.  term.clear()
  60.  for i = 1, #gomb do
  61.   paintutils.drawFilledBox(gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2, gomb[i].color)
  62.   term.setCursorPos(gomb[i].x+1, gomb[i].y)
  63.   print(gomb[i].szoveg)
  64.  end
  65.   term.setBackgroundColor(colors.black)
  66. end
  67.  
  68. function click(xpos, ypos, xs, ys, xe, ye)
  69.  if xpos < xs or xpos > xe or ypos < ys or ypos > ye then
  70.   return false
  71.  else
  72.   return true
  73.  end
  74. end
  75.  
  76. function jelszo()
  77.  if password == "123" then
  78.   password = "elfogadva"
  79.  elseif password == "0000" then
  80.   run = false
  81.  else
  82.   password = "megtagadva"
  83.  end
  84. end
  85.  
  86. function setter(i)
  87.  tempcolor = gomb[i].color
  88.  gomb[i].color = colors.white
  89.  kirajzol()
  90.  sleep(.2)
  91.  gomb[i].color = tempcolor
  92.  if i == 1 then
  93.   password = password..1
  94.  elseif i == 2 then
  95.   password = password..2
  96.  elseif i == 3 then
  97.   password = password..3
  98.  elseif i == 4 then
  99.   password = password..4
  100.  elseif i == 5 then
  101.   password = password..5
  102.  elseif i == 6 then
  103.   password = password..6
  104.  elseif i == 7 then
  105.   password = password..7
  106.  elseif i == 8 then
  107.   password = password..8
  108.  elseif i == 9 then
  109.   password = password..9
  110.  elseif i == 10 then
  111.   password = ""
  112.   kirajzol()
  113.  elseif i == 11 then
  114.   password = password..0
  115.  elseif i == 12 then
  116.   jelszo()
  117.  end
  118. end
  119.  
  120.  
  121. while run do
  122. kirajzol()
  123. local event, button, xpos, ypos = os.pullEvent("mouse_click")
  124.  for i=1, #gomb do
  125.   if click(xpos, ypos, gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2) then
  126.    setter(i)
  127.   end
  128.  end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement