Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local robot = require("robot")
- local computer = require('computer')
- local term = require("term")
- local note = require("note")
- local len,w = 8,8 -- длинна и ширина поля
- local s = 200 -- время ожидания созревания
- 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 check_energy() return computer.energy()>((computer.maxEnergy()*20)/100) end
- local function farm(len)
- for l = 1, len do
- if robot.detectDown() then
- robot.swingDown(); os.sleep(0.3)
- robot.down(); os.sleep(0.3)
- robot.swingDown(); os.sleep(0.3)
- robot.up()
- robot.forward()
- else robot.forward(); os.sleep(0.3)
- end
- end
- end
- local function work(len, side)
- turn = robot[(side == "right") and "turnRight" or "turnLeft"]
- farm(len)
- turn()
- robot.forward(); os.sleep(0.3)
- turn()
- end
- local function back (len, w, side)
- if side == "right" then
- robot.turnRight()
- for i = 1, w do
- robot.forward(); os.sleep(0.3)
- end
- else
- for i = 1, len do
- robot.forward(); os.sleep(0.3)
- end
- robot.turnLeft()
- for i = 1, w do
- robot.forward(); os.sleep(0.3)
- end
- end
- robot.turnRight()
- robot.forward(); os.sleep(0.3); robot.forward(); os.sleep(0.3)
- 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 trim(str)
- return string.gsub(str, "%s+","")
- 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
- local function StatEnrg()
- term.setCursor(15, 9)
- term.write("MAX заряд: "..(computer.maxEnergy()))
- term.setCursor(15, 10)
- term.write("Заряд батареи: "..(math.floor(computer.energy())))
- 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)
- wX = 11; wY = 3
- t = menu
- drawfn(clr, t, wX, wY)
- term.setCursor(17, 4)
- term.write("Если нужно засеять")
- term.setCursor(17, 5)
- term.write(" поле "..len.." на "..w)
- term.setCursor(21, 6)
- term.write("кактусами")
- term.setCursor(17, 8)
- term.write("в 1 слот положи - ░")
- term.setCursor(17, 9)
- term.write("в 2 слот положи - #")
- term.setCursor(17, 15)
- term.write("Засеять поле? y/n ")
- if trim(term.read())=="y" then
- n = m2
- song(n)
- clr = false; wX = 1; wY = 1
- t = background
- drawfn(clr, t, wX, wY)
- wX = 11; wY = 3; clr = false
- t = menu
- drawfn(clr, t, wX, wY)
- robot.forward(); os.sleep(0.3);robot.forward(); os.sleep(0.3)
- for ww = 1, w do
- for l = 1, len do
- if check_new then
- robot.down(); os.sleep(0.3);robot.down(); os.sleep(0.3);robot.down(); os.sleep(0.3)
- robot.select(1);robot.swingDown(0);robot.placeDown(0) -- поставить блок песка
- robot.up();robot.select(2);robot.placeDown(0) -- поставить блок кактуса
- robot.up(); robot.up(); robot.forward(); os.sleep(0.3)
- cacPl = cacPl + 1
- term.setCursor(15, 5)
- term.write("Посажено кактусов "..cacPl.." шт")
- check_new = false
- else robot.forward(); os.sleep(0.3)
- check_new = true
- end
- end
- if check_new then check_new = false else check_new = true end
- if ww % 2 == 1 then
- robot.turnLeft()
- robot.forward()
- robot.turnLeft()
- else
- robot.turnRight()
- robot.forward()
- robot.turnRight()
- end
- end
- back(len, w, (w % 2 == 0) and "right" or "Around")
- unload()
- wX=11; wY=3; clr = false
- t = menu
- drawfn(clr, t, wX, wY)
- n = m
- song(n)
- term.setCursor(15, 5)
- term.write("Посажено кактусов "..cacPl.." шт")
- term.setCursor(17, 7)
- term.write("Ожидаю первый урожай ")
- term.setCursor(20, 8)
- term.write(s.." секунд")
- for i=1, 10 do
- os.sleep(s/10)
- term.setCursor(20, 9)
- print("Прошло ",(10*i)..'%')
- end
- end
- ----------======= Цикл обработки поля =======-----------
- 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.forward(); os.sleep(0.3);robot.forward(); os.sleep(0.3)
- 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)
- for i=1, 10 do
- os.sleep(s/10)
- term.setCursor(20, 10)
- print("Прошло ",(10*i)..'%')
- StatEnrg()
- end
- if check_energy() then
- wX=11; wY=3; clr = false
- t = menu
- drawfn(clr, t, wX, wY)
- term.setCursor(17, 4)
- term.write("Низкий уровень заряда батареи!")
- term.setCursor(17, 6)
- term.write("Требуется подзарядка")
- n = m3
- song(n)
- repeat -- зарядка от солнечных батарей
- StatEnrg()
- until (computer.energy())==(computer.maxEnergy())
- end
- end
- ------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement