Advertisement
bob558

SG_Test_002

May 25th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. local com = require("component")
  2. local comp = require('computer')
  3. local sg = comp.stargate
  4. local term = require("term")
  5. local event=require('event')
  6. local gpu=require('component').gpu
  7. local disp = {gpu.getResolution()}
  8. local width = 80
  9. local height = 25
  10. local timeout = 1
  11. local key_net = 'W9MX-YD7-MF'
  12. local key_end = 0
  13. local SG_chek = false
  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. local function sg_addr()
  66.  
  67.   sg.dial(address)
  68.   os.sleep(10) -- время когда ворота открыты
  69.   sg.disconnect()
  70.   SG_chek = false
  71. end
  72.  
  73. local function sg()
  74.   even_OFF()
  75.  
  76.   -- проверить соединение
  77.   -- вывести предупреждение
  78.  
  79.   sg_addr()
  80. end
  81.  
  82. local function draw() -- вывести заставку
  83.   clr = true
  84.   wX = 1; wY = 1
  85.   t = frame
  86.   drawfn(clr, t, wX, wY) -- вывести фоновую заставку
  87.  
  88.   gpu.setBackground(color.stg3)  --  цвет фон
  89.   gpu.setForeground(color.back) --  цвет текст
  90.  
  91.   gpu.fill(14, 8, 20, 3, " ")
  92.   gpu.set(19, 9, "N E T H E R")
  93.   gpu.fill(14, 14, 20, 3, " ")
  94.   gpu.set(22, 15, "E N D")
  95.    --рисуем кнопку выхода
  96.   gpu.setBackground(color.exit)
  97.   gpu.set(2, 24, "exit")
  98.  
  99. end
  100.  
  101.  
  102.  
  103. local function touch(_,_, x, y)
  104.     if x>13 and x<35 and y>7 and y<11 then
  105.         local address = key_net
  106.         SG_chek = true
  107.         gpu.setBackground(color.stg3)  --  цвет фон
  108.         gpu.setForeground(color.back) --  цвет текст
  109.         gpu.set(20, 23, key_net)
  110.         os.sleep(0.5)
  111.         gpu.set(20, 23, "                ")
  112.        
  113.        
  114.         gpu.set(22, 21, "N E T H E R")
  115.         os.sleep(0.5)
  116.         gpu.set(22, 21, "           ")
  117.     elseif x>13 and x<35 and y>13 and y<17 then  
  118.        gpu.setBackground(color.stg3)  --  цвет фон
  119.        gpu.setForeground(color.back) --  цвет текст
  120.        gpu.set(22, 21, "E N D")
  121.        os.sleep(0.5)
  122.        gpu.set(22, 21, "     ")
  123.     elseif x>1 and x<6 and y==24 then    -- отладка
  124.             quit = true -- "exit"
  125.        
  126.     end
  127. end
  128.  
  129. local function even_ON()  event.listen('touch', touch); end
  130. local function even_OFF() event.ignore('touch', touch); end
  131.  
  132. -------- Программа ---------
  133.  
  134. local function main()
  135.   gpu.setBackground(color.stg)    -- цвет фон
  136.   gpu.setForeground(color.stg4)   -- цвет текст
  137.   draw()
  138.        
  139.   while true do
  140.        
  141.     os.sleep(timeout)
  142.     if SG_chek then even_OFF()
  143.       sg.dial(address)
  144.       os.sleep(10) -- время когда ворота открыты
  145.       sg.disconnect()
  146.       SG_chek = false; even_ON(); end
  147.     if quit then break end -- отладка
  148.   end
  149.  
  150.   os.sleep(2)
  151.   even_OFF()
  152.   gpu.setBackground(color.back)
  153.   gpu.setForeground(color.foreg)
  154.   gpu.setResolution(disp[1], disp[2])
  155. end
  156.  
  157. even_ON()
  158. gpu.setResolution(width, height) -- новое разрешение
  159. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement