diff --git a/Applications/Robot/Commander.lua b/Applications/Robot/Commander.lua new file mode 100644 index 00000000..58040056 --- /dev/null +++ b/Applications/Robot/Commander.lua @@ -0,0 +1,82 @@ +local robot = require("robot") +local robotAPI = require("robotAPI") + +local args = {...} + +------------------------------------------------------------------------------------------------------------------------ + +if #args < 0 then error("No arguments!") end +local commands = args[1] + +local symbols = {} +local symbolcounter = 1 + +------------------------------------------------------------------------------------------------------------------------ + +local function executeCommand(symbol) + if symbol == "f" then + robotAPI.move("forward") + elseif symbol == "r" then + robot.turnRight() + print("Поворачиваюсь направо!") + elseif symbol == "l" then + robot.turnLeft() + print("Поворачиваюсь налево!") + elseif symbol == "t" then + robot.turnAround() + print("Крррррууу-гом!") + elseif symbol == "u" then + robotAPI.move("up") + print("Поднимаюсь выше!") + elseif symbol == "d" then + robotAPI.move("down") + print("Опускаюсь ниже!") + elseif symbol == "m" then + robotAPI.move("forward") + robot.swing() + print("Копаю вперед!") + elseif symbol == "s" then + print("Копаю впереди!", robot.swing()) + + --Вообще потная хуйня, но работает, епта! + elseif tonumber(symbol) ~= nil then + local startNumber = symbol + local counter = 1 + for i = (symbolcounter + 1), #symbols do + local newNumber = tonumber(symbols[i]) + if newNumber then + startNumber = startNumber .. symbols[i] + counter = counter + 1 + else + break + end + end + startNumber = tonumber(startNumber) + + print("Выполняю "..startNumber.." раз команду "..symbols[symbolcounter + counter]) + for i = 1, startNumber do + executeCommand(symbols[symbolcounter + counter]) + end + + symbolcounter = symbolcounter + counter + end +end + +------------------------------------------------------------------------------------------------ + +for i = 1, #commands do + table.insert(symbols, string.sub(commands, i, i)) +end + +print(" ") +print("Начинаю работать!") +print(" ") + +while symbolcounter <= #symbols do + executeCommand(symbols[symbolcounter]) + symbolcounter = symbolcounter + 1 +end + +print(" ") +print("Работа завершена!") +print(" ") \ No newline at end of file diff --git a/Applications/Robot/HorizontalLazer.lua b/Applications/Robot/HorizontalLazer.lua new file mode 100644 index 00000000..0ad340a0 --- /dev/null +++ b/Applications/Robot/HorizontalLazer.lua @@ -0,0 +1,31 @@ +local robot = require("robot") +local component = require("component") +local robotAPI = require("robotAPI") +local inventory = component.inventory_controller + +local args = { ... } +if #args < 2 then print(" "); print("Использование: laser <длина> <ширина>"); print(" "); return end + +local width = tonumber(args[2]) +local length = tonumber(args[1]) + +for w = 1, width/2 do + for h = 1, length do + robot.useDown() + if h < length then robotAPI.move("forward") end + end + + robot.turnRight() + robotAPI.move("forward") + robot.turnRight() + + for h = 1, length do + robot.useDown() + if h < length then robotAPI.move("forward") end + end + + robot.turnLeft() + robotAPI.move("forward") + robot.turnLeft() +end + diff --git a/Applications/Robot/Installer.lua b/Applications/Robot/Installer.lua new file mode 100644 index 00000000..d08c7178 --- /dev/null +++ b/Applications/Robot/Installer.lua @@ -0,0 +1,2 @@ +local shell = require("shell") + diff --git a/Applications/Robot/laser.lua b/Applications/Robot/laser.lua index 6b61a8ae..123a0098 100644 --- a/Applications/Robot/laser.lua +++ b/Applications/Robot/laser.lua @@ -6,13 +6,13 @@ local inventory = component.inventory_controller local args = { ... } if #args < 2 then print(" "); print("Использование: laser <ширина> <высота>"); print(" "); return end -local width = args[1] -local height = args[2] +local width = tonumber(args[1]) +local height = tonumber(args[2]) for w = 1, width/2 do for h = 1, height do robot.use() - robotAPI.move("up") + if h < height then robotAPI.move("up") end end robot.turnRight() @@ -20,8 +20,8 @@ for w = 1, width/2 do robot.turnLeft() for h = 1, height do - robotAPI.move("down") robot.use() + if h < height then robotAPI.move("down") end end robot.turnRight() @@ -29,11 +29,3 @@ for w = 1, width/2 do robot.turnLeft() end -robot.turnLeft() - -for w = 1, width do - robotAPI.move("forward") -end - -robot.turnRight() -