Advertisement
efrim

Malafia

Oct 24th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. -- Bonemeal farm
  2.  
  3. REDSTONE_SIDE = "back" -- Сторона, к которой подключен модем
  4. DATA_FILE = "malafia.dat" -- Файл для сохранения данных
  5. TEMP_FILE = "malafia.temp" -- Временное хранилище
  6. REFRESH_RATE = 2        -- Seconds
  7.  
  8. BACKGROUND_COLOR = 1    -- White
  9. TEXT_COLOR = 32768      -- Black
  10.  
  11. scrX, scrY = term.getSize()
  12.  
  13. IsFarming = false
  14.  
  15. --------------------------------------------------
  16. -- Интерфейс
  17. --------------------------------------------------
  18.  
  19. function DrawBackground ()
  20.     term.setBackgroundColor(BACKGROUND_COLOR)
  21.     term.setTextColor(TEXT_COLOR)
  22.     term.setCursorBlink(false)
  23.     term.clear()
  24.     term.setCursorPos(1, 1)
  25.  
  26.     term.write("\t\t< Malafia Industries >")
  27. end
  28.  
  29. function WriteStats ()
  30.     term.setCursorPos(1, 3)
  31.     if IsFarming then term.write("Farming:\t\t\t\tTrue")
  32.     else term.write("Farming:\t\t\t\tFalse") end
  33. end
  34.  
  35. function WriteButtonsExplanation ()
  36.     term.setCursorPos(1, scrY-3)
  37.     term.write("F - farm, S - stop, X - shutdown")
  38. end
  39.  
  40. --------------------------------------------------
  41. -- Сохранение и загрузка
  42. --------------------------------------------------
  43.  
  44. function SaveToFile()
  45.     local file = fs.open(TEMP_FILE, "w")
  46.     file.writeLine(IsFarming .. "")
  47.     file.close()
  48.  
  49.     fs.delete(DATA_FILE)
  50.     fs.move(TEMP_FILE, DATA_FILE)
  51.  
  52.     return 0
  53. end
  54.  
  55. function LoadFromFile()
  56.     local file = fs.open(DATA_FILE, "r")
  57.     IsFarming = tonumber(file.readLine())
  58.     file.close()
  59.  
  60.     return 0
  61. end
  62.  
  63. --------------------------------------------------
  64. -- Главный луп
  65. --------------------------------------------------
  66.  
  67.  
  68. function main ()
  69.     if fs.exists(DATA_FILE) then
  70.         LoadFromFile()
  71.     end
  72.  
  73.     while true do
  74.         DrawBackground()
  75.         WriteStats()
  76.         WriteButtonsExplanation()
  77.  
  78.         local timeout = os.startTimer(REFRESH_RATE)
  79.         while true do
  80.            
  81.             event = {os.pullEvent()}
  82.  
  83.             if event[1] == "key" then
  84.                 if event[2] == 33 then              -- F - farm
  85.                     IsFarming = true
  86.                     redstone.setOutput(REDSTONE_SIDE, true)
  87.                     break
  88.                 elseif event[2] == 31 then          -- S - stop
  89.                     IsFarming = false
  90.                     redstone.setOutput(REDSTONE_SIDE, false)
  91.                     break
  92.                 elseif event[2] == 45 then          -- X - shutdown
  93.                     Shutdown()
  94.                 end
  95.             elseif event[1] == "timer" and event[2] == timeout then
  96.                 break
  97.             end
  98.         end
  99.     end
  100. end
  101.  
  102. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement