Advertisement
bob558

ferm_crops beta 01

Dec 25th, 2016
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- bob
  2.  
  3. local com = require("component")
  4. local robot = require("robot")
  5. local computer = require('computer')
  6. local term = require("term")
  7. local note = require("note")
  8. local len,w = 16,16   -- длинна и ширина поля
  9.   local s = 300 -- время ожидания созревания
  10.  
  11. local check_new, ch_n , side, n, cacPl = true, true, 0, 0, 0
  12. local wX, wY, draw, wXst, Vst, ch, clr = 5, 5, {" ", "#", "*", "█", "░"}, 0, 0, false, false
  13.  
  14. --------=== Графика ===--------
  15. local background = {1,99,50,0,1,99,44,2,2,1,1,99,4,0,1,99,4,2,2,1,99,38,2,2,1,2,1,1,0,
  16. 1,99,4,2,2,1,2,1,99,36,2,2,1,2,1,1,0,1,99,4,2,2,1,2,1,99,36,2,2,1,2,1,1,0,
  17. 1,99,4,2,2,1,2,1,99,36,2,99,4,1,1,0,1,99,4,2,99,4,1,99,34,2,1,2,2,1,99,4,0,
  18. 1,1,2,1,2,2,1,99,36,2,1,2,2,1,99,4,0,1,1,2,1,2,2,1,2,1,99,34,2,99,4,1,99,4,0,
  19. 1,1,2,1,2,2,1,2,1,99,36,2,2,1,2,1,1,0,1,1,2,1,2,99,4,1,99,36,2,2,1,2,1,1,0,
  20. 1,1,2,99,4,1,99,38,2,99,4,1,1,0,1,99,4,2,2,1,99,9,5,99,23,1,99,6,2,2,1,99,4,0,
  21. 1,99,4,2,2,1,99,5,5,99,31,1,1,2,2,1,99,4,0,5,5,1,1,2,2,1,1,5,99,42,0,5,99,50}
  22.  
  23. local signboard = {1,99,30,0,1,99,30,0,
  24. 4,1,1,4,1,99,4,4,4,1,4,1,1,4,1,4,4,4,1,4,1,1,4,1,1,1,4,4,1,0,
  25. 4,1,4,1,99,4,4,1,4,1,4,1,4,1,1,1,4,1,1,4,1,1,4,1,1,4,1,1,4,0,
  26. 4,1,4,1,1,1,4,1,1,4,1,4,1,4,1,1,1,4,1,1,1,4,1,4,1,4,1,99,4,0,
  27. 4,4,1,1,1,4,1,1,1,4,1,4,4,1,99,4,4,1,1,1,4,4,1,1,4,1,99,4,0,
  28. 4,1,4,1,1,4,99,5,1,4,1,4,1,1,1,4,1,99,4,4,1,1,4,1,99,4,0,
  29. 4,1,1,4,1,4,1,1,1,4,1,4,1,1,4,1,1,4,1,1,1,4,1,99,4,4,1,1,4,0,
  30. 4,1,1,4,1,4,1,1,1,4,1,4,1,1,4,1,1,4,1,1,4,1,99,6,4,4,1,}
  31.  
  32. local menu = {3,99,30,0,3,3,1,99,26,3,3,0,3,3,1,99,26,3,3,0,3,3,1,99,26,3,3,0,
  33. 3,3,1,99,26,3,3,0,3,3,1,99,26,3,3,0,3,3,1,99,26,3,3,0,3,3,1,99,26,3,3,0,3,99,30}
  34.  
  35. --------=== Звуки ===---------
  36. local m = {69,0.03,71,0.04,71,0.08,71,0.08,71,0.08,76,0.2,79,0.1}
  37. local m2 = {71,0.05,79,0.03}
  38. local m3 = {55,0.05,50,0.03}
  39.  
  40.  
  41. local function StatEnrg() -- показать заряд
  42.   term.setCursor(15, 9)
  43.   term.write("MAX заряд:     "..(computer.maxEnergy()))
  44.   term.setCursor(15, 10)
  45.   term.write("Заряд батареи: "..(math.floor(computer.energy())))
  46. end
  47.  
  48. local function charge() -- зарядка от зарядника справа
  49.   robot.turnRight()
  50.   robot.up()
  51.   robot.use(3)
  52.   robot.down()
  53.     repeat
  54.       os.sleep(0.5)
  55.       StatEnrg()
  56.     until (computer.energy())>((computer.maxEnergy())-50)
  57.   robot.up()
  58.   robot.use(3)
  59.   robot.down()
  60.   robot.turnLeft()
  61. end
  62.  
  63. function go()
  64.   while not robot.forward() do
  65.     os.sleep(0.01)
  66.   end
  67. end
  68.  
  69.  
  70. local function farm(len) -- собрать кропсы в длинну len
  71.   for l = 1, len do
  72.     while not robot.useDown() do
  73.       robot.useDown()
  74.     end
  75.     if l ~= len then go() end
  76.   end
  77. end
  78.  
  79. local function work(len, side)
  80.   turn = robot[(side == "right") and "turnRight" or "turnLeft"]
  81.   farm(len)
  82.   turn()
  83.   go()
  84.   turn()
  85. end
  86.  
  87. local function back (len, w, side) -- вернуться
  88.   if side == "right" then
  89.     robot.turnRight()
  90.     for i = 1, w do
  91.       go()
  92.     end
  93.   else
  94.     for i = 1, len do
  95.       go()
  96.     end
  97.     robot.turnLeft()
  98.       for i = 1, w do
  99.       go()
  100.       end
  101.   end
  102.   robot.turnRight()
  103.   go(); robot.down()
  104. end
  105.  
  106. local function unload() -- выгруза
  107.   for c = 1, 16 do
  108.     robot.select(c)
  109.     if robot.count() > 0 then
  110.   -- счетчик
  111.       robot.drop()
  112.     else
  113.       robot.select(1)
  114.       break
  115.     end
  116.   end
  117.   robot.turnAround()
  118. end
  119.  
  120. local function drawfn(clr, t, wX, wY) -- рисовать
  121.   if clr then
  122.     term.clear()
  123.     clr = false
  124.   end
  125.   wXst=wX
  126.   term.setCursor(wX, wY)
  127.   for i = 1, #t do
  128.     if t[i]==0 then
  129.       wY=wY+1
  130.       wX=wXst
  131.     elseif t[i]==99 then
  132.       ch=true
  133.       elseif ch then
  134.         ch=false
  135.         tt=t[i]
  136.         for a=1, tt-1 do
  137.           term.setCursor(wX, wY)
  138.           term.write(draw[Vst])
  139.           wX=wX+1
  140.         end
  141.       else
  142.         Vst=t[i]
  143.         term.setCursor(wX, wY)
  144.         term.write(draw[t[i]])
  145.         wX=wX+1
  146.     end
  147.   end
  148. end
  149.  
  150. local function song(n) -- сигналы
  151.   for i = 1, #n do
  152.   if ch_n then
  153.     ch_n = false
  154.     n1 = n[i]
  155.     else
  156.       ch_n = true
  157.       n2 = n[i]
  158.       note.play(n1, n[i])
  159.     end
  160.   end
  161. end
  162.  
  163.  
  164.  
  165. ----------- Main -----------------
  166. clr = true
  167. wX = 1; wY = 1
  168. t = background
  169. drawfn(clr, t, wX, wY) -- вывести фоновую заставку
  170. os.sleep(0.5)
  171. wX = 11; wY = 3
  172. clr = false
  173. t = signboard
  174. drawfn(clr, t, wX, wY)
  175. term.setCursor(20, 3)
  176. term.write("Ф Е Р М А")
  177. n = m2
  178. song(n)
  179. os.sleep(2)
  180.  
  181. ----------======= Цикл обработки поля =======-----------
  182.  
  183.  
  184. while true do
  185.   n = m2
  186.   song(n)
  187.   wX=11; wY=3; clr = false
  188.   t = menu
  189.   drawfn(clr, t, wX, wY)
  190.   term.setCursor(17, 4)
  191.   term.write("Ферма кропсов "..cacPl.." шт")
  192.   term.setCursor(17, 6)
  193.   term.write("между сбором урожая ")
  194.   term.setCursor(20, 7)
  195.   term.write(s.." секунд")
  196.   StatEnrg()
  197.   robot.up();go()
  198.   for i = 1, w do
  199.       work(len, (i % 2 == 0) and "right" or "left")
  200.   end
  201.     back(len, w, (w % 2 == 0) and "right" or "Around")
  202.     unload()
  203.     n = m
  204.     song(n)
  205.     charge()
  206.     for i=1, 10 do -- время между урожаями
  207.       os.sleep(s/10)
  208.       term.setCursor(20, 10)
  209.       print("Прошло ",(10*i)..'%')
  210.       StatEnrg()
  211.     end
  212. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement