Advertisement
VeLLeSSS

PaverBOT for OpenComputers

Oct 29th, 2016
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local com = require("component")
  2. local bot = require("robot")
  3. local term = require("term")
  4.  
  5. function digandplace() --операция укладывания
  6.     for i = 1, l do
  7.         bot.swingDown(0)
  8.         bot.placeDown(0)
  9.         bot.forward()
  10.     end
  11. end
  12. function work_l() -- для четных итераций
  13.     digandplace()
  14.     bot.turnLeft()
  15.     bot.forward()
  16.     bot.turnLeft()
  17.     bot.forward()
  18. end
  19. function work_r() -- для нечетных итераций
  20.     digandplace()
  21.     bot.turnRight()
  22.     bot.forward()
  23.     bot.turnRight()
  24.     bot.forward()
  25. end
  26. function check_material() -- функция для проверки кол-ва материала, для того чтобы бот не встал посреди работы
  27.     if bot.count() < l then
  28.         bot.select(bot.select()+1)
  29.     end
  30. end
  31.  
  32.  
  33. print('Введите длину дороги: ')
  34. l = tonumber(term.read()) -- длина дороги
  35. print('Введите ширину дороги: ')
  36. w = tonumber(term.read()) -- ширина дороги
  37. print('Спасибо! Робот приступил к работе.')
  38. for i = 1, w do -- укладываем
  39.     check_material()
  40.     if i % 2 == 0 then -- делаем проверку, чтобы робот поворачивал в нужном направлении
  41.         work_r()
  42.     else
  43.         work_l()
  44.     end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement