Advertisement
qwertyMAN_rus

Launcher [OC]

Jan 30th, 2016 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.69 KB | None | 0 0
  1. -- Автор: qwertyMAN
  2. -- Версия: 0.9 бета
  3.  
  4. local term              = require("term")
  5. local event             = require("event")
  6. local component         = require("component")
  7. local gpu               = component.gpu
  8.  
  9. -- устанавливаем переменные
  10. local games             = {}
  11. local Active_Line       = 1
  12. event.shouldInterrupt = function() return false end -- чтобы Alt + Ctrl + C не работал
  13.  
  14. -- настройки
  15. local border            = {1,1}             -- отступы от экрана
  16. local draw_versions     = false
  17. local colors            = {
  18.     Background          = 0x000000,
  19.     Foreground          = 0xffffff,
  20.     Active_Background   = 0x000000,
  21.     Active_Foreground   = 0x0000ff,
  22.     red                 = 0xff0000,
  23.     green               = 0x00ff00,
  24.     blue                = 0x0000ff,
  25.     yellow              = 0xffff00
  26. }
  27. local White_List        = {"QwertyMAN","electronic_steve"}  -- выдаём права администраторов
  28. local Black_List        = {"LeshaInc","Fingercomp"}         -- не разрешаем игрокам пользоваться компом
  29.  
  30. -- функция загрузки
  31. local function add_game(gm)
  32.     games[#games+1]     = require(gm)
  33. end
  34.  
  35. -- функции управления
  36. local command = {}
  37. command[28] = function()
  38.     if games[Active_Line].func then
  39.         local tb = games[Active_Line]
  40.         tb.Black_List   = Black_List
  41.         tb.White_List   = White_List
  42.         tb.colors       = colors
  43.         tb.border       = border
  44.         games[Active_Line].func(tb)
  45.     else
  46.         term.clear()
  47.         gpu.setForeground(colors.red)
  48.         print("game not found")
  49.         gpu.setForeground(colors.Foreground)
  50.         os.sleep(2)
  51.     end
  52. end
  53. command[23] = function()
  54.     term.clear()
  55.     if games[Active_Line].info then
  56.         gpu.setForeground(colors.green)
  57.         print(games[Active_Line].info)
  58.     else
  59.         gpu.setForeground(colors.red)
  60.         print("info if a game not found")
  61.     end
  62.     os.sleep(2)
  63.     gpu.setForeground(colors.Foreground)
  64. end
  65. command[200] = function()
  66.     Active_Line=math.max(1,Active_Line-1)
  67. end
  68. command[208] = function()
  69.     Active_Line=math.min(#games,Active_Line+1)
  70. end
  71. command[47] = function()
  72.     if draw_versions then
  73.         draw_versions = false
  74.     else
  75.         draw_versions = true
  76.     end
  77. end
  78.  
  79. -- загружаем игры
  80. add_game("Cube")
  81. add_game("snake")
  82. add_game("saper")
  83.  
  84. -- устанавливаем цвет текста и фона по умолчанию
  85. gpu.setBackground(colors.Background)
  86. gpu.setForeground(colors.Foreground)
  87.  
  88. -- отображаем список игр
  89. while true do
  90.     term.clear()
  91.     gpu.set(1+border[1], 1+border[2], "Games:")
  92.     for i=1,#games do
  93.         if not games[i].func then
  94.             gpu.setForeground(colors.red)
  95.         elseif tonumber(games[i].version) < 1 then
  96.             gpu.setForeground(colors.yellow)
  97.         else
  98.             gpu.setForeground(colors.green)
  99.         end
  100.         if draw_versions then
  101.             gpu.set(1+border[1], i+2+border[2], games[i].name.." v"..games[i].version)
  102.         else
  103.             gpu.set(1+border[1], i+2+border[2], games[i].name)
  104.         end
  105.     end
  106.     gpu.setBackground(colors.Active_Background)
  107.     gpu.setForeground(colors.Active_Foreground)
  108.     if draw_versions then
  109.         gpu.set(1+border[1], Active_Line+2+border[2], games[Active_Line].name.." v"..games[Active_Line].version)
  110.     else
  111.         gpu.set(1+border[1], Active_Line+2+border[2], games[Active_Line].name)
  112.     end
  113.     gpu.setBackground(colors.Background)
  114.     gpu.setForeground(colors.Foreground)
  115.     _,_,_, key, nick = event.pull("key_down")
  116.     local swich = true
  117.     for i=1, #Black_List do
  118.         if nick == Black_List[i] then
  119.             swich = false
  120.         end
  121.     end
  122.     if swich then
  123.         if key == 16 then -- позволяет выйти из программы всем кто в белом списке
  124.             for i=1, #White_List do
  125.                 if White_List[i]==nick then
  126.                     term.clear()
  127.                     print("Exit")
  128.                     os.sleep(2)
  129.                     term.clear()
  130.                     return
  131.                 end
  132.             end
  133.         elseif command[key] then
  134.             command[key]()
  135.         end
  136.     end
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement