Advertisement
bob558

farmer

Dec 6th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local robot = require("robot")
  2. local comp = require("computer")
  3.  
  4. local sizeY = 11 -- длинна поля перед роботом
  5. local sizeX = 11  -- ширина поля - обязательно всегда не четное число
  6.  
  7.  
  8. function harvest()
  9.   robot.up()
  10.   robot.forward()  
  11.   for y=1, sizeX do
  12.     robot.useDown()
  13.     robot.suckDown()
  14.     for x=1, (sizeY-1) do
  15.       robot.forward()
  16.       robot.useDown()
  17.       robot.suckDown()
  18.     end
  19.         -- разворот
  20.     if y%2 == 1 then
  21.           robot.turnLeft()
  22.           robot.forward()
  23.           robot.turnLeft()
  24.         else
  25.           robot.turnRight()
  26.           robot.forward()
  27.           robot.turnRight()
  28.         end
  29.   end
  30.  
  31.   -- возврат
  32.   for y=1, (sizeY-1) do
  33.     robot.forward()
  34.   end
  35.   robot.turnLeft()
  36.   for x=1, (sizeX-1) do
  37.     robot.forward()
  38.   end
  39.   robot.forward()
  40.   robot.turnRight()
  41.   robot.forward()
  42.   robot.turnAround()
  43.   robot.down()
  44. end
  45.  
  46. --выгрузка добра
  47. function unload()
  48.   robot.turnAround()
  49.   for c = 1, 16 do
  50.     robot.select(c)
  51.     if robot.count() > 0 then
  52.       robot.drop()
  53.     else
  54.       robot.select(1)
  55.       break
  56.     end
  57.   end
  58.   robot.turnLeft()
  59.   robot.up()
  60.   robot.use(3)
  61.   robot.down()
  62. print("Заряжаюсь")
  63.   for i=1, 10 do
  64.     os.sleep(4)
  65.    -- print("Ожидаю ")
  66.     print("Ожидаю ",(10*i)..'%')
  67.   end
  68.   robot.up()
  69.   robot.use(3)
  70.   robot.down()
  71.   robot.turnLeft()
  72. end
  73.  
  74. while true do
  75.   -- one hour sleeping
  76.   print("Начинаю работу")
  77.   for i=1, 10 do
  78.     os.sleep(50)
  79.    -- print("Ожидаю ")
  80.     print("Ожидаю ",(10*i)..'%')
  81.   end
  82.   --
  83.   harvest()
  84.     unload()
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement