Advertisement
bob558

SG_Test_003

May 25th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | None | 0 0
  1. local comp = require('component')
  2. local stargate = comp.stargate
  3. local term = require('term')
  4. local event=require('event')
  5. local gpu=require('component').gpu
  6. local disp = {gpu.getResolution()}
  7. local width = 80
  8. local height = 25
  9. local timeout = 1
  10. local key_neth = 'W9MX-YD7-MF'
  11. local key_end = 0
  12. local SG_chek = false
  13. local address = '0000'
  14.  
  15. local color = {
  16.     back=0x000000,
  17.     foreg=0xffffff,
  18.     exit=0xff0000,
  19.     stg=0xbebebe,
  20.     stg2=0xc0c0c0,
  21.     stg3=0x808080,
  22.     stg4=0x545454
  23. }
  24.  
  25. local draw = {" ", "█", "*", "█", "░"}
  26.  
  27. local frame = {2,99,80,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  28. 2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  29. 2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  30. 2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  31. 2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  32. 2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,2,1,99,43,2,1,99,34,2,0,
  33. 2,99,80}
  34.  
  35. local function drawfn(clr, t, wX, wY)
  36.   if clr then -- очитить экран?
  37.     term.clear()
  38.     clr = false
  39.   end
  40.   wXst=wX
  41.   term.setCursor(wX, wY)
  42.   for i = 1, #t do
  43.     if t[i]==0 then   -- Если "0" - конец строки - перейти на новую строку
  44.       wY=wY+1
  45.       wX=wXst
  46.     elseif t[i]==99 then  -- если 99 - напечатать N-е количество таких символов
  47.       ch=true
  48.       elseif ch then
  49.         ch=false
  50.         tt=t[i]
  51.         for a=1, tt-1 do   --цикл печати повторяющихся символов
  52.           term.setCursor(wX, wY)
  53.           term.write(draw[Vst])
  54.           wX=wX+1
  55.         end
  56.       else
  57.         Vst=t[i]
  58.         term.setCursor(wX, wY)
  59.         term.write(draw[t[i]])
  60.         wX=wX+1
  61.     end
  62.   end
  63. end
  64.  
  65.  
  66.  
  67. local function sg_addr() -- подключение к вратам
  68.  
  69.   stargate.dial(address)
  70.   gpu.set(20, 23, "соединение?"); os.sleep(0.5); gpu.set(20, 23, "                ") -- отладка
  71.   os.sleep(60) -- время когда врата открыты
  72.   stargate.disconnect()
  73.  
  74. end
  75.  
  76. local function starg()
  77.  
  78.   -- проверить соединение
  79.   -- вывести предупреждение
  80.  
  81.   sg_addr()
  82. end
  83.  
  84. local function draw() -- вывести заставку
  85.   clr = true
  86.   wX = 1; wY = 1
  87.   t = frame
  88.   drawfn(clr, t, wX, wY) -- вывести фоновую заставку
  89.  
  90.   gpu.setBackground(color.stg3)  --  цвет фон
  91.   gpu.setForeground(color.back) --  цвет текст
  92.  
  93.   gpu.fill(14, 8, 20, 3, " ")
  94.   gpu.set(19, 9, "N E T H E R")
  95.   gpu.fill(14, 14, 20, 3, " ")
  96.   gpu.set(22, 15, "E N D")
  97.    --рисуем кнопку выхода
  98.   gpu.setBackground(color.exit)
  99.   gpu.set(2, 24, "exit")
  100.  
  101. end
  102.  
  103.  
  104.  
  105. local function touch(_,_, x, y)
  106.     if x>13 and x<35 and y>7 and y<11 then
  107.         local address = key_neth
  108.         SG_chek = true
  109.         gpu.setBackground(color.stg3)  --  цвет фон
  110.         gpu.setForeground(color.back) --  цвет текст
  111.         gpu.set(20, 23, key_neth); os.sleep(0.5); gpu.set(20, 23, "                ") -- отладка
  112.                
  113.         gpu.set(22, 21, "N E T H E R");os.sleep(0.5);gpu.set(22, 21, "           ") -- отладка
  114.     elseif x>13 and x<35 and y>13 and y<17 then  
  115.        gpu.setBackground(color.stg3)  --  цвет фон
  116.        gpu.setForeground(color.back) --  цвет текст
  117.        gpu.set(22, 21, "E N D");os.sleep(0.5);gpu.set(22, 21, "     ") -- отладка
  118.     elseif x>1 and x<6 and y==24 then    -- отладка
  119.             quit = true -- "exit"
  120.        
  121.     end
  122. end
  123.  
  124. local function even_ON()  event.listen('touch', touch); end
  125. local function even_OFF() event.ignore('touch', touch); end
  126.  
  127. -------- Программа ---------
  128.  
  129. local function main()
  130.  
  131.   gpu.setBackground(color.stg)    -- цвет фон
  132.   gpu.setForeground(color.stg4)   -- цвет текст
  133.   draw()
  134.        
  135.   while true do
  136.        
  137.     os.sleep(timeout)
  138.     if SG_chek then even_OFF(); starg(); SG_chek = false; even_ON(); end
  139.     if quit then break end -- отладка
  140.   end
  141.  
  142.   even_OFF()
  143.   gpu.setBackground(color.back)
  144.   gpu.setForeground(color.foreg)
  145.   gpu.setResolution(disp[1], disp[2])
  146. end
  147.  
  148. even_ON()
  149. gpu.setResolution(width, height) -- новое разрешение
  150. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement