Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local modem = component.modem
- local event = require("event")
- local thread = require("thread")
- local term = require("term")
- local computer = require("computer")
- local fs = require("filesystem")
- -- Переменные
- local size = 4
- local x, y
- local control_port = 1245
- local threads = {}
- local foreground = 0xffffff
- local background = 0xaaaa00
- local table_monitors = {}
- local main_monitor
- local otvet_port = 2356
- local table_scan
- local cool_mobs
- local options
- local table_record
- local file_monitors
- --Переменные радаров
- local r_com_port = 456
- local r_otv_port = 123
- local radars = {{},{},{},{},{},{},{},{}}
- --переменные таблицы
- local ygol_0_0 = "┌"
- local ygol_0_1 = "┐"
- local ygol_1_0 = "└"
- local ygol_1_1 = "┘"
- local horiz_line = "─"
- local vert_line = "│"
- local default_perec = "┼"
- local up_perec = "┴"
- local down_perec = "┬"
- local right_perec = "├"
- local left_perec = "┤"
- -- Функции
- function error_out()
- size = 1
- for address in component.list("screen") do
- switch_monitor(address)
- term.clear()
- x, y = gpu.getResolution()
- j=1
- for i = math.floor(y/4), math.floor(3*y/4) do
- for z = (i-math.floor(y/4))%10+1,x,10 do
- if(j == 1) then
- j = 2
- gpu.setBackground(0xff0000)
- elseif(j==2) then
- j = 1
- gpu.setBackground(0xffff00)
- end
- gpu.fill(z,i,10,1," ")
- end
- end
- end
- end
- function decode(message)
- otvet = message
- return message
- end
- function code(message)
- otvet = message
- return otvet
- end
- function filtr(table)
- end
- function pre_initial()
- if(not fs.exists("/files")) then
- fs.makeDirectory("/files")
- end
- if(not fs.exists("/files/options")) then
- file = io.open("/files/options","w")
- file:write("size: 4\n")
- file:write("foreground: 0xffffff\n")
- file:write("background: 0xaaaa00\n")
- file:write("control_port: 1245\n")
- file:write("otvet_port: 2356\n")
- file:flush()
- file:close()
- end
- if(not fs.exists("/files/table_players")) then
- file = io.open("/files/table_players","w")
- file:flush()
- file:close()
- end
- if( not fs.exists("/files/table_monitors")) then
- file = io.open("/files/table_monitors","w")
- for address in component.list("screen") do
- if(component.screen.address ~= address) then
- file:write(address.."\n")
- end
- end
- file:close()
- end
- table_records = io.open("/files/table_players","a")
- file = io.open("/files/options","r")
- while(true) do
- data = nil
- data = file:read("*l")
- if(data == nil) then
- break
- end
- temp = data:find(":")
- option = data:sub(1,temp-1)
- if(option == "size") then
- size = tonumber(data:sub(temp+2))
- elseif(option=="foreground") then
- foreground = tonumber(data:sub(temp+2))
- elseif(option=="background") then
- background = tonumber(data:sub(temp+2))
- elseif(option=="control_port") then
- control_port = tonumber(data:sub(temp+2))
- elseif(option == "otvet_port") then
- otvet_port = tonumber(data:sub(temp+2))
- end
- end
- file:close()
- i = 1
- for line in io.lines("/files/table_monitors") do
- table_monitors[i] = line
- i = i+1
- end
- for address in component.list("screen") do
- for i = 1, #table_monitors do
- if(address ~= table_monitors[i]) then
- component.setPrimary("screen",address)
- main_monitor = address
- end
- end
- end
- end
- function initial()
- modem.broadcast(otvet_port,code("Ok"))
- i = 1
- for address in component.list("screen")
- do
- if(main_monitor ~= address) then
- table_monitors[i] = address
- i=i+1
- end
- component.invoke(address,"turnOn")
- end
- term.clear()
- switch_monitor(table_monitors[1])
- term.clear()
- if(not(modem.isOpen(control_port))) then
- modem.open(control_port)
- end
- end
- function scan(address,isPlyers)
- if(isPlayers) then
- return component.invoke(address,"getPlayers")
- else
- return component.invoke(address,"getMobs")
- end
- end
- function output_table()
- print("Не готово")
- end
- function edit_size(new_size)
- size = new_size
- file = io.open("/files/options","r")
- os.sleep(0.5)
- proverca =false
- while(true) do
- temp = file:read("*l")
- if(temp == nil) then
- proverca =true
- break
- end
- temp_nb = temp:find(":")
- temp_label = temp:sub(1,temp_nb-1)
- print(temp_label)
- if(temp_label == "size") then
- break
- end
- end
- file:close()
- file = io.open("/files/options","a")
- if(proverca) then
- file:seek("end")
- file:write("\nsize: "..tostring(size))
- else
- file:seek("set",temp_nb+1)
- file:write(size.." \n")
- end
- file:close()
- for i = 1, #table_monitors do
- switch_monitor(table_monitors[i])
- term.clear()
- term.write("Готово\n")
- end
- os.sleep(2)
- end
- function switch_monitor(new_monitor)
- if(new_monitor == nil)
- then
- gpu.bind(main_monitor)
- gpu.setForeground(0xffffff)
- gpu.setBackground(0x000000)
- temp_x, temp_y = gpu.maxResolution()
- gpu.setResolution(temp_x, temp_y)
- component.setPrimary("screen",main_monitor)
- else
- gpu.bind(new_monitor)
- gpu.setForeground(foreground)
- gpu.setBackground(background)
- set_scale_monitor(new_monitor)
- component.setPrimary("screen",new_monitor)
- end
- end
- function set_scale_monitor(address)
- temp_x,temp_y = component.invoke(address,"getAspectRatio")
- proportion = (temp_x*2 - 0.5)/(temp_y-0.25)
- x,y = gpu.maxResolution()
- if(x/y>proportion) then
- x = math.floor(proportion*y)
- else
- y = math.floor(x/proportion)
- end
- x = math.floor(x/size)
- y = math.floor(y/size)
- gpu.setResolution(x,y)
- end
- --Сам код
- pre_initial()
- initial()
- viem_energ = thread.create(function() while(true) do x, y = gpu.getResolution() gpu.set(1,y, tostring(computer.energy())) os.sleep(0.5) end end)
- while(true) do
- term.write("Введите команду\n")
- _,_,_,_,_,command = event.pull("modem_message")
- command = decode(command)
- if(command == "exit") then
- modem.broadcast(otvet_port,code("Ok"))
- foreground = 0xffffff
- background = 0x000000
- for i = 1 , #table_monitors do
- switch_monitor(table_monitors[i])
- term.clear()
- component.invoke(table_monitors[i],"turnOff")
- end
- viem_energ:kill()
- switch_monitor()
- term.clear()
- modem.close(control_port)
- os.exit()
- elseif(command == "test_start") then
- modem.broadcast(otvet_port,code("ok"))
- term.clear()
- elseif(command=="full_exit") then
- modem.broadcast(otvet_port,code("ok"))
- foreground = 0xffffff
- background = 0x000000
- for i = 1, #table_monitors do
- switch_monitor(table_monitors[i])
- term.clear()
- component.invoke(table_monitors[i],"turnOff")
- end
- switch_monitor()
- viem_energ:kill()
- computer.shutdown()
- elseif(command == "Изменить размер") then
- term.clear()
- term.write("Изменение размера\n")
- modem.broadcast(otvet_port,code("размер"))
- switch_monitor(table_monitors[1])
- _,_,_,_,_, otvet = event.pull(30,"modem_message")
- otvet = decode(otvet)
- if(otvet ==nil) then
- term.write("Ошибка!!!\n")
- os.sleep(2)
- term.clear()
- else
- edit_size(tonumber(otvet))
- switch_monitor(table_monitors[1])
- term.clear()
- end
- elseif(command == "Скан 1") then --До и после сканирование
- for address in component.list("radar") do
- table_scan[address] = scan
- end
- elseif(command == "test") then
- error_out()
- os.sleep(10)
- else
- term.write("Неверная команда\n")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement