Advertisement
Guest User

run

a guest
Jan 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local com = require("component")
  2. local eve = require("event")
  3. local mod = com.modem
  4. local gpu = com.gpu
  5. local scr = com.screen
  6.  
  7. local X, Y
  8. local B, F
  9. local port = 3341
  10. local hide = false
  11.  
  12. local keycode =  {
  13.                   [49]  = true, --1
  14.                   [50]  = true, --2
  15.                   [51]  = true, --3
  16.                   [113] = true, --Q
  17.                   [119] = true, --W
  18.                   [101] = true, --E
  19.                   [97]  = true, --A
  20.                   [115] = true, --S
  21.                   [100] = true, --D
  22.                   [122] = true, --Z
  23.                   [120] = true, --X
  24.                   [99]  = true  --C
  25.                  }
  26.  
  27. local keychar =  {
  28.                   [49]  = "1",
  29.                   [50]  = "2",
  30.                   [51]  = "3",
  31.                   [113] = "Q",
  32.                   [119] = "W",
  33.                   [101] = "E",
  34.                   [97]  = "A",
  35.                   [115] = "S",
  36.                   [100] = "D",
  37.                   [122] = "Z",
  38.                   [120] = "X",
  39.                   [99]  = "C"
  40.                  }
  41.  
  42. function clrscr()
  43.   gpu.fill(1,1,X,Y," ")
  44. end
  45.  
  46. function sysInit()
  47.   gpu.bind(scr.address)
  48.   X,Y = gpu.maxResolution()
  49.   B = gpu.getBackground()
  50.   F = gpu.getForeground()
  51.   gpu.setBackground(0xBBBBFF)
  52.   gpu.setForeground(0xAA22AA)
  53.   clrscr()
  54. end
  55.  
  56. function sysDeinit()
  57.   gpu.setBackground(B)
  58.   gpu.setForeground(F)
  59.   clrscr()
  60. end
  61.  
  62. function printInfo()
  63.   gpu.set(3,2,"Управление движением:")
  64.   gpu.set(3,3,"---------------------")
  65.   gpu.set(3,4,"W - вперед")
  66.   gpu.set(3,5,"S - назад")
  67.   gpu.set(3,6,"A - влево")
  68.   gpu.set(3,7,"D - вправо")
  69.   gpu.set(3,8,"Q - вниз")
  70.   gpu.set(3,9,"E - вверх")
  71.  
  72.   gpu.set(3,12,"Действия:")
  73.   gpu.set(3,13,"-----------------------------")
  74.   gpu.set(3,14,"1 - выбор стороны (Вкл\\Выкл)")
  75.   gpu.set(3,15,"2 - стырить")
  76.   gpu.set(3,16,"3 - [не назначено]")
  77.  
  78.   gpu.set(40,2,"Функции (Вкл/Выкл):")
  79.   gpu.set(40,3,"------------------------")
  80.   gpu.set(40,4,"Z - вернуться назад")
  81.   gpu.set(40,5,"X - пройти путь повторно")
  82.   gpu.set(40,6,"C - [не назначено]")
  83.  
  84.   gpu.set(40,12,"Прочее:")
  85.   gpu.set(40,13,"------------------------------")
  86.   gpu.set(40,14,"Space     - управление экраном")
  87.   gpu.set(40,15,"Backspace - выход")
  88. end
  89.  
  90.  
  91. sysInit()
  92. printInfo()
  93. while true do
  94.   local _,_,key,_,name = eve.pull("key_down")
  95.  
  96.   if (keycode[key]==true) then
  97.     mod.broadcast(port,keychar[key])
  98.     gpu.set(70,24,keychar[key])
  99.   end
  100.  
  101.   if (key==32) then
  102.     if (hide==true) then
  103.       gpu.setResolution(X,Y)
  104.       os.sleep(0.2)
  105.       printInfo()
  106.       hide = false
  107.     else
  108.       gpu.setResolution(1,1)
  109.       os.sleep(0.2)
  110.       hide = true
  111.     end
  112.   end
  113.  
  114.   if (key==8) then break end
  115. end
  116. sysDeinit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement