Advertisement
LeslieCraft

[HUN] Minecraft, Reactor vezerlo

Feb 6th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. function cls()
  2.     term.setCursorPos(1,1)
  3.     term.clear()
  4. end
  5.  
  6. --[[ Local variables ]]--
  7.  
  8. local termWidth, termHeight = term.getSize()
  9. local selectedItem = 1
  10. local inMainMenu = true
  11. local inOtherMenu = false
  12. local reactor = false
  13. local reac = "Off"
  14. local onoff = 0
  15. local reacJel = "right"
  16. local monJel = "top"
  17. local monJel2 = "back"
  18. local monitor = true
  19. local mon = "On"
  20. local mononoff = 1
  21. local tempJel = "left"
  22. local temp = rs.getInput(tempJel)
  23. local temperature = ""
  24.  
  25. --[[ Menu Methods ]]--
  26.  
  27. function Choice1()
  28.     onoff = math.fmod( onoff+1, 2 )
  29.     if onoff == 0 then
  30.         reac = "Off"
  31.         reactor = false
  32.         rs.setOutput(reacJel, reactor)
  33.     elseif onoff == 1 then
  34.         reac = "On"
  35.         reactor = true
  36.         rs.setOutput(reacJel, reactor)
  37.     else
  38.         cls()
  39.         rs.setOutput(reacJel, false)
  40.         print("ERROR 1: reactor: " .. reactor)
  41.         reactor = false
  42.         sleep(2)
  43.     end
  44. end
  45.  
  46. function Choice2()
  47.     mononoff = math.fmod( mononoff+1, 2 )
  48.     if mononoff == 0 then
  49.         mon = "Off"
  50.         monitor = false
  51.         rs.setOutput(monJel, monitor)
  52.         rs.setOutput(monJel2, monitor)
  53.     elseif mononoff == 1 then
  54.         mon = "On"
  55.         monitor = true
  56.         rs.setOutput(monJel, monitor)
  57.         rs.setOutput(monJel2, monitor)
  58.     else
  59.         cls()
  60.         rs.setOutput(monJel, false)
  61.         rs.setOutput(monJel2, false)
  62.         print("ERROR 1: monitor: " .. monitor)
  63.         monitor = false
  64.         sleep(2)
  65.     end
  66. end
  67.  
  68. function Option1()
  69.     term.clear()
  70.     term.setCursorPos(1,1)
  71.     print("Hi")
  72.     sleep(2)
  73.     selectedItem = 1
  74. end
  75.  
  76. function Back()
  77.     selectedItem = 1
  78.     inOtherMenu = false
  79. end
  80.  
  81. function Exit()
  82.     rs.setOutput(reacJel, false)
  83.     cls()
  84.     inMainMenu = false
  85. end
  86.  
  87. --[[ Menu Definitions ]]--
  88.  
  89. mainMenu = {
  90.     [1] = { text = "Reactor on/off: ", handler = Choice1 },
  91.     [2] = { text = "Monitor on/off: ", handler = Choice2 },
  92.     [3] = { text = "Exit", handler = Exit }
  93. }
  94.  
  95. otherMenu = {
  96.     [1] = { text = "Option 1", handler = Option1 },
  97.     [2] = { text = "Back", handler = Back }
  98. }
  99.  
  100. --[[ Printing Methods ]]--
  101.  
  102. function printMenu(menu)
  103.     for i=1,#menu do
  104.         if i == selectedItem then
  105.             print(">> "..menu[i].text)
  106.         else
  107.             print("   "..menu[i].text)
  108.         end
  109.     end
  110. end
  111.  
  112. --[[ Handler Methods ]]--
  113.  
  114. function onKeyPressed( key, menu )
  115.     if key == keys.enter then
  116.         onItemSelected(menu)
  117.     elseif key == keys.up then
  118.         if selectedItem > 1 then
  119.             selectedItem = selectedItem - 1
  120.         end
  121.     elseif key == keys.down then
  122.         if selectedItem < #menu then
  123.             selectedItem = selectedItem +1
  124.         end
  125.     end
  126. end
  127.  
  128. function onItemSelected(menu)
  129.     menu[selectedItem].handler()
  130. end
  131.  
  132. --[[ Main Method ]]--
  133.  
  134. function main()
  135.     while inMainMenu do
  136.         term.clear()
  137.         term.setCursorPos(1,1)
  138.         printMenu(mainMenu)
  139.         term.setCursorPos(20,1)
  140.         print(reac .. " " .. temperature)
  141.         term.setCursorPos(20,2)
  142.         print(mon)
  143.         event, key = os.pullEvent("key")
  144.         onKeyPressed(key, mainMenu)
  145.     end
  146. end
  147.  
  148. --[[  Main program  ]]--
  149.  
  150.  
  151. rs.setOutput(monJel, monitor)
  152. rs.setOutput(reacJel, reactor)
  153. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement