Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- bob
- local com = require("component")
- local robot = require("robot")
- local computer = require('computer')
- local term = require("term")
- local note = require("note")
- local len,w = 16,16 -- длинна и ширина поля
- local s = 300 -- время ожидания созревания
- local check_new, ch_n , side, n, cacPl = true, true, 0, 0, 0
- local wX, wY, draw, wXst, Vst, ch, clr = 5, 5, {" ", "#", "*", "█", "░"}, 0, 0, false, false
- --------=== Графика ===--------
- 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,
- 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,
- 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,
- 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,
- 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,
- 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,
- 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}
- local signboard = {1,99,30,0,1,99,30,0,
- 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,
- 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,
- 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,
- 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,
- 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,
- 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,
- 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,}
- 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,
- 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}
- --------=== Звуки ===---------
- local m = {69,0.03,71,0.04,71,0.08,71,0.08,71,0.08,76,0.2,79,0.1}
- local m2 = {71,0.05,79,0.03}
- local m3 = {55,0.05,50,0.03}
- local function StatEnrg() -- показать заряд
- term.setCursor(15, 9)
- term.write("MAX заряд: "..(computer.maxEnergy()))
- term.setCursor(15, 10)
- term.write("Заряд батареи: "..(math.floor(computer.energy())))
- end
- local function charge() -- зарядка от зарядника справа
- robot.turnRight()
- robot.up()
- robot.use(3)
- robot.down()
- repeat
- os.sleep(0.5)
- StatEnrg()
- until (computer.energy())>((computer.maxEnergy())-50)
- robot.up()
- robot.use(3)
- robot.down()
- robot.turnLeft()
- end
- function go()
- while not robot.forward() do
- os.sleep(0.01)
- end
- end
- local function farm(len) -- собрать кропсы в длинну len
- for l = 1, len do
- while not robot.useDown() do
- robot.useDown()
- end
- if l ~= len then go() end
- end
- end
- local function work(len, side)
- turn = robot[(side == "right") and "turnRight" or "turnLeft"]
- farm(len)
- turn()
- go()
- turn()
- end
- local function back (len, w, side) -- вернуться
- if side == "right" then
- robot.turnRight()
- for i = 1, w do
- go()
- end
- else
- for i = 1, len do
- go()
- end
- robot.turnLeft()
- for i = 1, w do
- go()
- end
- end
- robot.turnRight()
- go(); robot.down()
- end
- local function unload() -- выгруза
- for c = 1, 16 do
- robot.select(c)
- if robot.count() > 0 then
- -- счетчик
- robot.drop()
- else
- robot.select(1)
- break
- end
- end
- robot.turnAround()
- end
- local function drawfn(clr, t, wX, wY) -- рисовать
- if clr then
- term.clear()
- clr = false
- end
- wXst=wX
- term.setCursor(wX, wY)
- for i = 1, #t do
- if t[i]==0 then
- wY=wY+1
- wX=wXst
- elseif t[i]==99 then
- ch=true
- elseif ch then
- ch=false
- tt=t[i]
- for a=1, tt-1 do
- term.setCursor(wX, wY)
- term.write(draw[Vst])
- wX=wX+1
- end
- else
- Vst=t[i]
- term.setCursor(wX, wY)
- term.write(draw[t[i]])
- wX=wX+1
- end
- end
- end
- local function song(n) -- сигналы
- for i = 1, #n do
- if ch_n then
- ch_n = false
- n1 = n[i]
- else
- ch_n = true
- n2 = n[i]
- note.play(n1, n[i])
- end
- end
- end
- ----------- Main -----------------
- clr = true
- wX = 1; wY = 1
- t = background
- drawfn(clr, t, wX, wY) -- вывести фоновую заставку
- os.sleep(0.5)
- wX = 11; wY = 3
- clr = false
- t = signboard
- drawfn(clr, t, wX, wY)
- term.setCursor(20, 3)
- term.write("Ф Е Р М А")
- n = m2
- song(n)
- os.sleep(2)
- ----------======= Цикл обработки поля =======-----------
- while true do
- n = m2
- song(n)
- wX=11; wY=3; clr = false
- t = menu
- drawfn(clr, t, wX, wY)
- term.setCursor(17, 4)
- term.write("Ферма кропсов "..cacPl.." шт")
- term.setCursor(17, 6)
- term.write("между сбором урожая ")
- term.setCursor(20, 7)
- term.write(s.." секунд")
- StatEnrg()
- robot.up();go()
- for i = 1, w do
- work(len, (i % 2 == 0) and "right" or "left")
- end
- back(len, w, (w % 2 == 0) and "right" or "Around")
- unload()
- n = m
- song(n)
- charge()
- for i=1, 10 do -- время между урожаями
- os.sleep(s/10)
- term.setCursor(20, 10)
- print("Прошло ",(10*i)..'%')
- StatEnrg()
- end
- end
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement