Advertisement
ZNZNCOOP

OC_FarmerBuilder

Dec 18th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.81 KB | None | 0 0
  1. robot= require('robot')
  2. c= require('component')
  3. SOUTH= 0 -- юг +z
  4. EAST= 3 -- восток +x
  5. NORTH= 2 -- север -z
  6. WEST= 1 -- запад  -x
  7. Max_World_Y= 300
  8. Min_World_Y= 0
  9. local SEEDCELL= 15
  10. io.write('Side:')
  11. local sides= io.read()+0
  12. io.write('X:')
  13. local x= io.read()+0
  14. io.write('Y:')
  15. local y= io.read()+0
  16. io.write('Z:')
  17. local z= io.read()+0
  18.  
  19. function turnLeft()
  20.         sides= sides-1
  21.         if (sides<0) then sides= 3 end
  22.         robot.turnLeft()
  23. end
  24. function turnRight()
  25.         sides= sides+1
  26.         if (sides>3) then sides= 0 end
  27.         robot.turnRight()
  28. end
  29. function forward()
  30.         if (robot.detect()) then
  31.        return false
  32.         end
  33.         if (sides == SOUTH) then
  34.            z=z+1
  35.         elseif (sides == EAST) then
  36.            x= x+1
  37.         elseif (sides == NORTH) then
  38.            z= z-1
  39.         elseif(sides == WEST) then
  40.            x= x-1
  41.         end
  42.         robot.forward()
  43. end
  44. function up()
  45.    if (y>=Max_World_Y) then
  46.           y= Max_World_Y
  47.    elseif (robot.detectUp() ~= true) then
  48.           y= y+1
  49.           robot.up()
  50.    end
  51.  
  52. end
  53. function down()
  54.         if (y<=Min_World_Y) then
  55.           y= Min_World_Y
  56.    elseif (robot.detectDown() ~= true) then
  57.           y= y-1
  58.           robot.down()
  59.    end
  60. end
  61.  
  62. function turns(side)
  63.    while true do
  64.       if (side == sides) then
  65.          break
  66.       end
  67.       turnRight()
  68.    end
  69. end
  70.  
  71. function right()
  72.    turnRight()
  73.    robot.swing()
  74.    forward()
  75.    turnRight()
  76. end
  77. function left()
  78.    turnLeft()
  79.    robot.swing()
  80.    forward()
  81.    turnLeft()
  82. end
  83.  
  84.  
  85. function gotos(X,Y,Z,side)
  86.    while true do
  87.       if (y < Y) then
  88.          if (robot.detectUp() ~= true) then
  89.              up()
  90.          else
  91.             robot.digUp()
  92.          end
  93.       elseif(y > Y) then
  94.          if(robot.detectDown() ~= true) then
  95.             down()
  96.          else
  97.             robot.digDown()
  98.          end
  99.       elseif(y == Y) then
  100.          break
  101.       end
  102.    end
  103.    while true do
  104.       if (z < Z) then
  105.          turns(0)
  106.          if (robot.detect() ~= true) then
  107.             forward()
  108.          else
  109.             robot.dig()
  110.          end
  111.       end
  112.       if (z > Z) then
  113.          turns(2)
  114.          if (robot.detect() ~= true) then
  115.              forward()  
  116.          else
  117.             robot.dig()
  118.          end
  119.       end
  120.       if (z == Z) then
  121.          break
  122.       end
  123.    end
  124.    while true do
  125.       if (x < X) then
  126.          turns(3)
  127.          if (robot.detect() ~= true) then
  128.              forward()  
  129.          else
  130.             robot.dig()
  131.          end        
  132.       end
  133.       if (x > X) then
  134.          turns(1)
  135.          if (robot.detect() ~= true) then
  136.             forward()
  137.          else
  138.             robot.dig()
  139.          end
  140.       end
  141.       if (x == X) then
  142.          break
  143.       end
  144.    end
  145.   turns(side)
  146. end
  147.  
  148. function createField(x,y)
  149.    local Y= 0
  150.    local stats= 0
  151.    local waterCellX= 8
  152.    local waterCellY= 7
  153.    while Y<=y do
  154.       local X= 0
  155.       Y= Y+1
  156.       waterCellY= waterCellY+1
  157.       while X<=x do
  158.         print(waterCellX,waterCellY)
  159.         if (waterCellX >= 8 and waterCellY >= 8) then
  160.            waterCellX= 0
  161.            robot.swingDown()
  162.         end
  163.         if (X+1 ~= x) then
  164.            forward()
  165.         end
  166.          X= X+1
  167.          waterCellX= waterCellX+1
  168.       end
  169.       if (stats == 0) then
  170.          right()
  171.          stats= 1
  172.       elseif (stats == 1) then
  173.          left()
  174.          stats= 0
  175.       end
  176.       if (waterCellY >= 8) then
  177.          waterCellY= 0
  178.       end
  179.    end
  180. end
  181. local startX= x
  182. local startY= y
  183. local startZ= z
  184. local sidess= sides
  185. local stats= 0
  186. local length_x,length_y= 0,0
  187. io.write('Enter length X:')
  188. length_x= io.read()+0
  189. io.write('Enter length Y:')
  190. length_y= io.read()+0
  191. stat= true
  192.  
  193. createField(length_x,length_y)
  194. gotos(0,0,0,sidess)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement