Advertisement
Guest User

startup

a guest
Apr 22nd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | None | 0 0
  1. local m = peripheral.wrap("right")
  2. local r = peripheral.wrap("left")
  3. local cb = peripheral.wrap("top")
  4.  
  5. local menu_options = {
  6.   [1] = {text="Demarrer", color=colors.green},
  7.   [2] = {text="Arreter", color=colors.red},
  8.   [3] = {text="Quitter", color=colors.white}
  9. }
  10.  
  11. local termX, termY = term.getSize()
  12. local alert = false
  13. local maxtemp = 100
  14. local error = ""
  15.  
  16. local function menuDraw(selected)
  17.   local yPos = termY/2 - #menu_options/2
  18.   for index, data in pairs(menu_options) do
  19.     menu_options[index].bounds = {
  20.       x1 = termX/2 - (#data.text+4)/2;
  21.       x2 = termX/2 + (#data.text+4)/2;
  22.       y = yPos;
  23.     }
  24.     term.setTextColor(data.color)
  25.     term.setCursorPos(data.bounds.x1, data.bounds.y)
  26.    
  27.     local text = index==selected and "[ "..data.text.." ]" or "  "..data.text.."  "
  28.     term.write(text)
  29.     yPos = yPos+1
  30.   end
  31. end
  32.  
  33. local function verifheat()
  34.   a,b,c,i = r.get(1)
  35.   if a == nil then
  36.     return true
  37.   end
  38.   term.setTextColor(colors.orange)
  39.   term.setCursorPos(1,termY-1)
  40.   term.write("Temp : "..i["heat"].."         ")
  41.   if i["heat"]>=maxtemp then
  42.     if alert == false then
  43.       alert = true
  44.       cb.say("Reacteur en surchauffe !")
  45.     end
  46.     redstone.setOutput("back", true)
  47.     m.transmit(1,1,"stop")
  48.     term.setTextColor(colors.red)
  49.     term.setCursorPos(1,termY)
  50.     term.write("Le reacteur est arrete.         ")
  51.     return false
  52.   else
  53.     if alert == true then
  54.       alert = false
  55.       cb.say("Reacteur revenu a la normale !")
  56.     end
  57.     redstone.setOutput("back", false)
  58.     return false
  59.   end
  60. end
  61.  
  62. term.clear()
  63.  
  64. local selector = 1
  65.  
  66. while true do
  67.   menuDraw(selector)
  68.   if verifheat() then
  69.     error = "Mauvaise carte dans le lecteur !"
  70.     break
  71.   end
  72.   os.startTimer(0.2)
  73.   local e = {os.pullEvent()}
  74.   if e[1] == "key" then
  75.     if e[2] == keys.down then
  76.       selector = selector < #menu_options and selector+1 or 1
  77.     elseif e[2] == keys.up then
  78.       selector = selector > 1 and selector-1 or #menu_options
  79.     elseif e[2] == keys.enter then
  80.       if selector == 1 then
  81.         m.transmit(1, 1, "start")
  82.         term.setTextColor(colors.green)
  83.         term.setCursorPos(1, termY)
  84.         term.write("Le reacteur est demarre.     ")
  85.       elseif selector == 2 then
  86.         m.transmit(1, 1,"stop")
  87.         term.setTextColor(colors.red)
  88.         term.setCursorPos(1, termY)
  89.         term.write("Le reacteur est arrete.      ")
  90.       elseif selector == 3 then
  91.         break
  92.       end
  93.     end
  94.   end
  95. end
  96.  
  97. term.clear()
  98. term.setTextColor(colors.white)
  99. term.setCursorPos(1,1)
  100. m.transmit(1, 1, "stop")
  101. redstone.setOutput("back", false)
  102. if error == "" then
  103.   print("Fin du programme, reacteur arrete.")
  104. else
  105.   print(error)
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement