Advertisement
Guest User

startup

a guest
Feb 2nd, 2013
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. function resetCode()
  2.   one = false
  3.   two = false
  4.   three = false
  5.   four = false
  6.   five = false
  7.   six = false
  8.   seven = false
  9.   eight = false
  10.   nine = false
  11.   passwordString = " "
  12. end
  13. resetCode()
  14. --------------------------------------------
  15. local mon = peripheral.wrap("top")
  16. mon.setTextScale(1)
  17. mon.setTextColor(colors.white)
  18. local button={}
  19. mon.setBackgroundColor(colors.black)
  20.      
  21. function setTable(name, func, xmin, xmax, ymin, ymax)
  22.    button[name] = {}
  23.    button[name]["func"] = func
  24.    button[name]["active"] = false
  25.    button[name]["xmin"] = xmin
  26.    button[name]["ymin"] = ymin
  27.    button[name]["xmax"] = xmax
  28.    button[name]["ymax"] = ymax
  29. end
  30.  
  31. function funcName()
  32.    print("You clicked buttonText")
  33. end
  34.        
  35. function fillTable()
  36.    setTable("1", password1, 1, 1, 1, 1)
  37.    setTable("2", password2, 3, 3, 1, 1)
  38.    setTable("3", password3, 5, 5, 1, 1)
  39.    setTable("4", password4, 1, 1, 3, 3)
  40.    setTable("5", password5, 3, 3, 3, 3)
  41.    setTable("6", password6, 5, 5, 3, 3)
  42.    setTable("7", password7, 1, 1, 5, 5)
  43.    setTable("8", password8, 3, 3, 5, 5)
  44.    setTable("9", password9, 5, 5, 5, 5)
  45.    setTable("*", passwordValid, 7, 7, 5, 5)
  46.    setTable("C", resetCode, 7, 7, 1, 1)
  47.   -- setTable("OtherButton is COOL!", funcName, 5, 35, 10, 12)
  48. end    
  49.  
  50. function password1()
  51.   one = true
  52.   print("ping")
  53.   passwordString = passwordString.."1"
  54. end
  55.  
  56. function password2()
  57.   two = true
  58.   print("ping")
  59.   passwordString = passwordString.."2"
  60. end
  61.  
  62. function password3()
  63.   three = true
  64.   print("ping")
  65.   passwordString = passwordString.."3"
  66. end
  67.  
  68. function password4()
  69.   four = true
  70.   print("ping4")
  71.   passwordString = passwordString.."4"
  72. end
  73.  
  74. function password5()
  75.   five = true
  76.   print("ping5")
  77.   passwordString = passwordString.."5"
  78. end
  79.  
  80. function password6()
  81.   six = true
  82.   passwordString = passwordString.."6"
  83. end
  84.  
  85. function password7()
  86.   seven = true
  87.   passwordString = passwordString.."7"
  88. end
  89.  
  90. function password8()
  91.   eight = true
  92.   passwordString = passwordString.."8"
  93. end
  94.  
  95. function password9()
  96.   nine = true
  97.   passwordString = passwordString.."9"
  98. end
  99.  
  100. function fill(text, color, bData)
  101.    mon.setBackgroundColor(color)
  102.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  103.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  104.    for j = bData["ymin"], bData["ymax"] do
  105.       mon.setCursorPos(bData["xmin"], j)
  106.       if j == yspot then
  107.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  108.             if k == xspot then
  109.                mon.write(text)
  110.             else
  111.                mon.write(" ")
  112.             end
  113.          end
  114.       else
  115.          for i = bData["xmin"], bData["xmax"] do
  116.             mon.write(" ")
  117.          end
  118.       end
  119.    end
  120.    mon.setBackgroundColor(colors.black)
  121. end
  122.      
  123. function screen()
  124.    local currColor
  125.    for name,data in pairs(button) do
  126.       local on = data["active"]
  127.       if on == true then
  128.         currColor = colors.lime
  129.         currColor = colors.red
  130.       else currColor = colors.red
  131.       end
  132.       fill(name, currColor, data)
  133.    end
  134. end
  135.      
  136. function checkxy(x, y)
  137.    for name, data in pairs(button) do
  138.       if y>=data["ymin"] and  y <= data["ymax"] then
  139.          if x>=data["xmin"] and x<= data["xmax"] then
  140.             data["func"]()
  141.             data["active"] = not data["active"]
  142.             print(name)
  143.          end
  144.       end
  145.    end
  146. end
  147.      
  148. function heading(text)
  149.    w, h = mon.getSize()
  150.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  151.    mon.write(text)
  152. end
  153.      
  154. fillTable()
  155. print(passwordString)
  156. function passwordValid()
  157.   if one == true then
  158.     print("test")
  159.    end
  160.   if passwordString == " 1234" then
  161.     print("password accepted")
  162.     print(passwordString)
  163.     print("pass")
  164.     redstone.setOutput("right", true)
  165.     sleep(10)
  166.     redstone.setOutput("right", false)
  167.     passwordString = " "
  168.   else
  169.     print(passwordString)
  170.     print("fail")
  171.   end
  172.  
  173.   one = false
  174.   two = false
  175.   three = false
  176.   four = false
  177.   five = false
  178.   six = false
  179.   seven = false
  180.   eight = false
  181.   nine = false
  182.   print("code reset")
  183. end
  184.  
  185. passwordValid()
  186. print("PINGALING")
  187.  
  188. while true do
  189.    mon.clear()
  190.    heading(" ")
  191.    screen()
  192.    local e,side,x,y = os.pullEvent("monitor_touch")
  193.    print(x..":"..y)
  194.    checkxy(x,y)
  195.    sleep(.1)
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement