Advertisement
nezd

Reactor

Apr 15th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. --Импортируем библиотеки и объявлем переменные
  2. component = require("component")
  3. filesystem = require("filesystem")
  4. term = require("term")
  5. event = require("event")
  6. gpuadr = component.gpu.address
  7. gpu = component.proxy(gpuadr)
  8. stdresx, stdresy = gpu.getResolution()
  9. showcaseswitch = true
  10. --Создаем функции, связанные с ID
  11.  
  12. function createReactorRegistry ()
  13.     filesystem.makeDirectory("/etc/reactor/")
  14.     print("Введите ID реактора")
  15.     reactorid = io.read()
  16.     local idcfg = io.open("/etc/reactor/reactorid", "w")
  17.     io.output(idcfg)
  18.     io.write(reactorid)
  19.     io.close(idcfg)
  20.     getReactorID()
  21. end
  22. function getReactorID ()
  23.     if filesystem.exists("/etc/reactor/reactorid") then
  24.         --Запись о реакторе есть, записываем ID в переменную
  25.         local idcfg = io.open("/etc/reactor/reactorid")
  26.         io.input(idcfg)
  27.         reactorid = io.read()
  28.         print("Использую реактор с ID:" .. reactorid)
  29.         reactor = component.proxy(reactorid)
  30.     else
  31.         --Записи о реакторе нет, записываем ID в файл
  32.         createReactorRegistry()
  33.     end
  34. end
  35.  
  36. --Создаем главную функцию
  37. function showcase ()
  38.     getReactorID()
  39.     gpu.setResolution(30, 4) --Ставим маленькое расширение для большого текста
  40.     os.sleep(2)
  41.     event.listen("key_up", settingsentrence) --Нажатие любой клавиши
  42.     while true do
  43.         if showcaseswitch == false then break end --Подготовка к переходу в настройки, выключение главного режима
  44.         local running = reactor.getActive() --Получаем состояние
  45.         local preftemp = reactor.getFuelTemperature() --Получаем температуру топлива
  46.         local prectemp = reactor.getCasingTemperature() --Получаем температуру корпуса
  47.         local ctemp = math.floor(prectemp) --Округляем температуру корпуса
  48.         local ftemp = math.floor(preftemp) --Округляем температуру топлива
  49.         if running == true then
  50.             print("Реактор включен")
  51.         end
  52.         if running == false then
  53.             print("Реактор выключен")
  54.         end
  55.         print("Температура топлива:" .. ftemp)
  56.         term.write("Температура корпуса:" .. ctemp)
  57.         os.sleep(1)
  58.         term.clear()
  59. end end
  60. --Вход в настройки
  61. function settingsentrence ()
  62.     event.ignore("key_up", settingsentrence)
  63.     showcaseswitch = false
  64.     ::settingsentrence::
  65.     gpu.setResolution(stdresx, stdresy)
  66.     term.clear()
  67.     if filesystem.exists("/etc/reactor/settingspass") then
  68.         print("Введите пароль")
  69.         enteredpass = io.read()
  70.         local passfile = io.open("/etc/reactor/settingspass")
  71.         io.input(passfile)
  72.         realpass = io.read()
  73.         if realpass == enteredpass then
  74.             io.close(passfile)
  75.             settings()
  76.         else
  77.             goto settingsentrence
  78.         end
  79.     else
  80.         print("Придумайте пароль")
  81.         pass = io.read()
  82.         local passfile = io.open("/etc/reactor/settingspass", "w")
  83.         io.output(passfile)
  84.         io.write(pass)
  85.         io.close(passfile)
  86.        
  87.     end
  88. end
  89. --Текст по центру
  90. function centerText (a)
  91.     x, y = term.getCursor()
  92.     x = math.floor(stdresx / 2) - string.len(a)
  93.     term.setCursor(x, y)
  94.     term.write(a)
  95. end
  96. --Настройки
  97. function settings ()
  98.     enteredpass = nil
  99.     realpass = nil
  100.     print("Настройки")
  101.     print("1.Поменять пароль")
  102.     print("2.Поменять ID реактора")
  103.     print("3.Включить или выключить реактор")
  104.     print("4.Вывести топливо")
  105.     print("5.Вывести отходы")
  106.     print("6.Вернуться в главный экран")
  107.     print("7.Выход из программы")
  108.     term.write("Команда:")
  109.     uinput = io.read()
  110. end
  111. --Загрузили библиотеки и функции начинаем создавать ивент для входа в настройки
  112. showcase()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement