Advertisement
fenixrus61

Cane_farm_by_Fenixrus

Jul 10th, 2014
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. --[[
  2.  
  3. Cactus farm by Fenixrus
  4. We must download this prorgam to your Robot, for using and run her.
  5.  
  6. ]]--
  7.  
  8. r = require("robot")
  9. slot = 1
  10.  
  11. function need_block()
  12.     if r.count(slot) == 0 then
  13.         slot = slot + 1
  14.         r.select(slot)
  15.     end
  16. end
  17. function turnRightPlace()
  18.     need_block()
  19.     r.turnRight()
  20.     r.forward()
  21.     r.turnRight()
  22.     r.placeDown()
  23. end
  24. function turnLeftPlace()
  25.     need_block()
  26.     r.turnLeft()
  27.     r.forward()
  28.     r.turnLeft()
  29.     r.placeDown()
  30. end
  31. function place(count)
  32.     r.select(slot)
  33.     local i
  34.     for i=1,count do
  35.         need_block()
  36.         r.forward()
  37.         r.placeDown()
  38.     end
  39. end
  40.  
  41. function useDown()
  42.     forward(3)
  43.     r.down()
  44.     r.useDown()
  45.     r.turnAround()
  46.     r.up()
  47.     forward(3)
  48.     r.turnRight()
  49. end
  50.  
  51. function forward(count)
  52.     for i=1,count do
  53.         r.forward()
  54.     end
  55. end
  56.  
  57. function us_aro(count)
  58.     forward(count)
  59.     r.useDown()
  60.     r.turnAround()
  61.     forward(count)
  62.     r.turnLeft()
  63. end
  64.  
  65.  
  66. function swing_forw(count)
  67.     for i=1,count do
  68.         r.swing()
  69.         r.forward()
  70.         r.swingDown()
  71.     end
  72. end
  73.  
  74. function swing_Turn_Left()
  75.     r.turnLeft()
  76.     r.swing()
  77.     r.forward()
  78.     r.swingDown()
  79.     r.turnLeft()
  80. end
  81.  
  82. function swing_Turn_Right()
  83.     r.turnRight()
  84.     r.swing()
  85.     r.forward()
  86.     r.swingDown()
  87.     r.turnRight()
  88. end
  89.  
  90.  
  91. function place_cane()
  92.     r.placeDown()
  93.     place(7)
  94.     turnRightPlace()
  95.     place(7)
  96. end
  97.  
  98. function gathering_Counter_Clockwise()
  99.     swing_forw(8)
  100.     swing_Turn_Left()
  101.     swing_forw(7)
  102.     for i=1,2 do
  103.         r.turnRight()
  104.         r.forward()
  105.         r.swing()
  106.         r.forward()
  107.         r.swingDown()
  108.         r.turnRight()
  109.         swing_forw(7)  
  110.         swing_Turn_Left()
  111.         swing_forw(7)
  112.     end
  113.  
  114.     r.forward()
  115.     r.turnAround()
  116.  
  117. end
  118.  
  119. function gathering_Clockwise()
  120.     swing_forw(8)
  121.     swing_Turn_Right()
  122.     swing_forw(7)
  123.     for i=1,2 do
  124.         r.turnLeft()
  125.         r.forward()
  126.         r.swing()
  127.         r.forward()
  128.         r.swingDown()
  129.         r.turnLeft()
  130.         swing_forw(7)
  131.         swing_Turn_Right()
  132.         swing_forw(7)
  133.     end
  134.     r.forward()
  135.     r.turnAround()
  136.    
  137. end
  138.  
  139. function build_area()
  140.     local i
  141.     print("Building area is start")
  142.     r.up()
  143.     place(10)
  144.     turnRightPlace()
  145.     place(9)
  146.     turnLeftPlace()
  147.     for i=1,5 do
  148.         place(9)
  149.         turnRightPlace()
  150.         place(9)
  151.     if i < 5 then
  152.         turnLeftPlace()
  153.     end
  154.     end
  155.     print("Building area is finish")
  156. end
  157.  
  158. function build_frame()
  159.     print("Building frame  is start")
  160.     r.up()
  161.     r.turnRight()
  162.     place(11)
  163.     r.turnRight()
  164.     place(9)
  165.     r.turnRight()
  166.     place(11)
  167.     r.turnRight()
  168.     place(9)
  169.     print("Building frame is finish")
  170. end
  171.  
  172. function build_sand()
  173.     print("Placement of sand  is start")
  174.     slot = 4
  175.     r.select(slot)
  176.     r.back()
  177.     for i=1,3 do
  178.         r.turnRight()
  179.         r.forward()
  180.         r.forward()
  181.         r.turnRight()
  182.         r.placeDown()
  183.         place(7)
  184.         turnLeftPlace()
  185.         place(7)
  186.     end
  187.     print("Placement of sand  is finish")
  188. end
  189.  
  190. function build_water()
  191.     print("Placement of water is start")
  192.     r.turnRight()
  193.     r.forward()
  194.     r.useDown()
  195.     r.forward()
  196.     r.turnLeft()
  197.     useDown()
  198.     us_aro(4)
  199.     useDown()
  200.     us_aro(7)
  201.     useDown()
  202.     us_aro(10)
  203.     print("Placement of water is finish")
  204. end
  205.  
  206. function build_cane()
  207.     print("Placement of cane is start")
  208.  
  209.     slot = 5
  210.     r.select(slot)
  211.     r.up()
  212.     r.turnLeft()
  213.     forward(2)
  214.     for i=1,3 do
  215. print(i)
  216.         r.turnLeft()
  217.         r.placeDown()
  218.         place(7)
  219.         turnRightPlace()
  220.         place(7)
  221.         r.turnLeft()
  222.         if i < 3 then forward(2) end
  223.     end
  224.     r.turnLeft()
  225.     r.back()
  226.     r.up()
  227.     print("Placement of cane is finish")
  228. end
  229.  
  230. function work()
  231.     print("Start working")
  232.     slot = 1
  233.     r.select(slot)
  234.     local j = 1
  235.     local Even = false
  236.     while true do
  237.         print("cycle: ",j)
  238.     if j%2 == 0 then    Even = true
  239.         else    Even = false    end
  240.     local drop = false
  241.         if j == 4 or j == 8 then drop = true end
  242.         if drop then
  243.             r.down()
  244.             for i=1,10 do
  245.                
  246.                 r.select(i)
  247.                 r.dropDown()
  248.             end
  249.             r.up()
  250.             slot = 1
  251.             r.select(slot)
  252.         end
  253.  
  254.             if r.detect() then
  255.                 if Even then
  256.                     gathering_Clockwise()  
  257.                     j = j + 1
  258.                 else
  259.                     gathering_Counter_Clockwise()
  260.                     j = j + 1
  261.                 end
  262.             end
  263.  
  264.         if j > 10 then  j = 1   end
  265.         os.sleep(60)
  266.         end
  267. end
  268.  
  269. print("Hello!")
  270. print("I am start building")
  271. build_area()
  272. build_frame()
  273. build_sand()
  274. build_water()
  275. build_cane()
  276. work()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement