Advertisement
Exylar

Accès temporaire

May 1st, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.11 KB | None | 0 0
  1. ---------------------------------------------------
  2. --                                               --
  3. --           Crée par Thomas Bastien             --
  4. --                                               --
  5. ---------------------------------------------------
  6.  
  7. os.pullEvent = os.pullEventRaw
  8.  
  9. local modem = peripheral.wrap("back")
  10. local modemxp = peripheral.wrap("top")
  11. local Action = "MenuPrincipal"
  12. local xp = false
  13. local a = 1
  14. local b = 59
  15. local c = 59
  16. local breakTimer = false
  17.  
  18. function DrawMenuPrincipal()
  19.     img = paintutils.loadImage("menu")
  20.     paintutils.drawImage(img,1,1)
  21.     term.setCursorPos(1,1)
  22.     term.setBackgroundColor(colors.black)
  23.     term.setTextColor(colors.yellow)
  24.     print("Ferme à Or")
  25.     term.setCursorPos(41,1)
  26.     term.setBackgroundColor(colors.black)
  27.     term.setTextColor(colors.yellow)
  28.     print("Coopérative")
  29.     term.setCursorPos(20,4)
  30.     term.setBackgroundColor(colors.black)
  31.     term.setTextColor(colors.yellow)
  32.     print("Temps Restant")
  33.     term.setCursorPos(14,14)
  34.     term.setBackgroundColor(colors.red)
  35.     term.setTextColor(colors.yellow)
  36.     print("Arrêter")
  37.     term.setCursorPos(31,14)
  38.     term.setBackgroundColor(colors.green)
  39.     term.setTextColor(colors.yellow)
  40.     print("Utiliser")
  41.     term.setCursorPos(23,17)
  42.     term.setBackgroundColor(colors.black)
  43.     term.setTextColor(colors.yellow)
  44.     print("Mode Xp")
  45.     term.setCursorPos(22,6)
  46.     term.setBackgroundColor(colors.black)
  47.     term.setTextColor(colors.white)
  48.     local aText = ""
  49.     local bText = ""
  50.     local cText = ""
  51.     if a == 1 then
  52.         a=0
  53.     end
  54.     if a < 10 then
  55.         aText = "0"..a
  56.     else
  57.         aText = ""..a
  58.     end
  59.     if b < 10 then
  60.         bText = "0"..b
  61.     elseif b == 60 then
  62.          bText = "0"
  63.     else
  64.         bText = ""..b
  65.     end
  66.     if c < 10 then
  67.         cText = "0"..c
  68.     elseif c==60 then
  69.         cText = "0"
  70.     else
  71.         cText = ""..c
  72.     end
  73.     print(aText..":"..bText..":"..cText)
  74.     if timerlaunch == false then
  75.     time()
  76.     end
  77.      
  78. end
  79.  
  80. function DrawMenuAdmin()
  81.     imgadmin = paintutils.loadImage("menuadmin")
  82.     paintutils.drawImage(imgadmin,1,1)
  83.     term.setCursorPos(1,1)
  84.     term.setBackgroundColor(colors.black)
  85.     term.setTextColor(colors.yellow)
  86.     write("Menu Admin")
  87.     term.setCursorPos(41,1)
  88.     term.setBackgroundColor(colors.black)
  89.     term.setTextColor(colors.yellow)
  90.     print("Coopérative")
  91.     term.setCursorPos(12,5)
  92.     term.setBackgroundColor(colors.black)
  93.     term.setTextColor(colors.yellow)
  94.     print("Ferme")
  95.     term.setCursorPos(34,5)
  96.     term.setBackgroundColor(colors.black)
  97.     term.setTextColor(colors.yellow)
  98.     print("Terminal")
  99.     term.setCursorPos(12,9)
  100.     term.setBackgroundColor(colors.black)
  101.     term.setTextColor(colors.yellow)
  102.     print("Ouvrir")
  103.     term.setCursorPos(12,12)
  104.     term.setBackgroundColor(colors.black)
  105.     term.setTextColor(colors.yellow)
  106.     print("Fermer")
  107.     term.setCursorPos(34,9)
  108.     term.setBackgroundColor(colors.black)
  109.     term.setTextColor(colors.yellow)
  110.     print("Terminer")
  111.     term.setCursorPos(35,12)
  112.     term.setBackgroundColor(colors.black)
  113.     term.setTextColor(colors.yellow)
  114.     print("Reboot")
  115. end
  116.  
  117. function MenuAff()
  118.     if Action == "MenuPrincipal" then
  119.         shell.run("clear")
  120.         DrawMenuPrincipal()
  121.     elseif Action == "MenuAdmin" then
  122.         shell.run("clear")
  123.         DrawMenuAdmin()
  124.     end
  125. end
  126.  
  127. function time()
  128.         term.setCursorPos(22,6)
  129.         term.setBackgroundColor(colors.black)
  130.         term.setTextColor(colors.white)
  131.         print("01:00:00")
  132. end
  133. timerlaunch = false
  134. function timer()
  135.     while true do
  136.         MenuAff()
  137.     if Action == "MenuPrincipal" then
  138.         time()
  139.     end
  140.         a=0
  141.         b=59
  142.         c=59
  143.         while true do
  144.              event = os.pullEvent()
  145.             if event == "StartTimer" then
  146.                  break
  147.             end
  148.         end
  149.         timerlaunch = true
  150.         local na = a
  151.         local nb = b
  152.         local nc = c
  153.         for i=na,0,-1 do
  154.             if breakTimer == true then
  155.                 break
  156.             end
  157.             for j=nb,0,-1 do
  158.                 if breakTimer == true then
  159.                      break
  160.                 end
  161.                 for k=nc,0,-1 do
  162.                     if breakTimer == true then
  163.                         break
  164.                     end
  165.                         a=i
  166.                         b=j
  167.                         c=k
  168.                         local aText = ""
  169.                         local bText = ""
  170.                         local cText = ""
  171.                         if a == 1 then
  172.                             a=0
  173.                         end
  174.                         if a < 10 then
  175.                             aText = "0"..a
  176.                         else
  177.                             aText = ""..a
  178.                         end
  179.                         if b < 10 then
  180.                             bText = "0"..b
  181.                         elseif b == 60 then
  182.                              bText = "0"
  183.                         else
  184.                             bText = ""..b
  185.                         end
  186.                         if c < 10 then
  187.                             cText = "0"..c
  188.                         elseif c==60 then
  189.                             cText = "0"
  190.                         else
  191.                             cText = ""..c
  192.                         end
  193.                     if Action == "MenuPrincipal" then
  194.                         term.setCursorPos(22,6)
  195.                         term.setBackgroundColor(colors.black)
  196.                         term.setTextColor(colors.white)
  197.                         print(aText..":"..bText..":"..cText)
  198.                     end
  199.                     sleep(1)
  200.                 end
  201.             end
  202.         end
  203.         breakTimer = false
  204.         timerlaunch=false
  205.         modem.transmit(14,14,"false")
  206.     end
  207. end
  208.  
  209. function startup()
  210.     modemxp.open(15)
  211.     modemxp.transmit(15,15,inspect)
  212.     Action = "MenuPrincipal"
  213.     while true do
  214.         event, p1, p2, p3 = os.pullEvent()
  215.         if p2 == nil then
  216.         else
  217.             if event == "mouse_click" then
  218.                 term.setTextColor(colors.white)
  219.                 term.setCursorPos(1,7)
  220.                 --print("X:" ..p2.." Y:"..p3)
  221.                 if Action == "MenuPrincipal" then
  222.                     if p2 >= 30 and p2 <= 39 and p3 == 14 then
  223.                         term.setCursorPos(15, 10)
  224.                         term.setBackgroundColor(colors.lightGray)
  225.                         term.setTextColor(colors.red)
  226.                         print("Timer en fonctionnement")
  227.                         os.queueEvent("StartTimer")
  228.                         modem.transmit(14,14,"true")
  229.                     elseif p2 >= 13 and p2 <= 22 and p3 == 14 then
  230.                         breakTimer = true
  231.                         modemxp.transmit(15,15,inspect)
  232.                         xp = false
  233.                     elseif p2>= 51 and p3 == 1 then
  234.                          Action = "MenuAdmin"
  235.                          MenuAff()
  236.                     elseif p2 >= 21 and p2<= 30 and p3 == 17 then
  237.                         xp = not xp
  238.                         if xp == true then
  239.                         paintutils.drawLine(22,17,30,17,colors.black)
  240.                         term.setBackgroundColor(colors.black)
  241.                         term.setTextColor(colors.yellow)
  242.                         term.setCursorPos(23,17)
  243.                         print("Mode Or")
  244.                         modemxp.transmit(15,15,"true")
  245.                         sleep(0.5)
  246.                         elseif xp == false then
  247.                         paintutils.drawLine(22,17,30,17,colors.black)
  248.                         term.setBackgroundColor(colors.black)
  249.                         term.setTextColor(colors.yellow)
  250.                         term.setCursorPos(23,17)
  251.                         print("Mode Xp")
  252.                         modemxp.transmit(15,15,"true")
  253.                         sleep(0.5)
  254.                         end            
  255.                     end
  256.                 elseif Action == "MenuAdmin" then
  257.                     if p2 >= 51 and p3 == 1 then
  258.                         Action = "MenuPrincipal"
  259.                         MenuAff()
  260.                     elseif p2 >= 7 and p2 <= 22 and p3 == 9 then
  261.                         modem.transmit(14,14,"true")
  262.                     elseif p2 >= 7 and p2 <= 22 and p3 == 12 then
  263.                         modem.transmit(14,14,"false")
  264.                     elseif p2 >= 30 and p2 <= 45 and p3 == 9 then
  265.                         Action = "Terminer"
  266.                         term.setBackgroundColor(colors.black)
  267.                         shell.run("clear")
  268.                         shell.run("shell")
  269.                     elseif p2 >= 30 and p2 <= 45 and p3 == 12 then
  270.                         os.reboot()
  271.                     end
  272.                 end
  273.             end
  274.         end
  275.     end
  276. end
  277. MenuAff()
  278.  
  279. function diskEject()
  280.     while true do
  281.         event, side = os.pullEvent()
  282.         if event == "disk" then
  283.         disk.eject(side)
  284.         end
  285.     end
  286. end
  287. parallel.waitForAll(startup,timer,diskEject)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement