new cow breeder app
This commit is contained in:
@@ -5,6 +5,7 @@ local Util = require('util')
|
|||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
local term = _G.term
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
@@ -19,12 +20,20 @@ local sensor = device['plethora:sensor'] or
|
|||||||
local function getCowCount()
|
local function getCowCount()
|
||||||
local blocks = sensor.sense()
|
local blocks = sensor.sense()
|
||||||
|
|
||||||
|
local grown = 0
|
||||||
|
local babies = 0
|
||||||
|
|
||||||
Util.filterInplace(blocks, function(v)
|
Util.filterInplace(blocks, function(v)
|
||||||
if v.name == 'Cow' then
|
if v.name == 'Cow' then
|
||||||
|
grown = grown + (v.y > -.5) and 1 or 0
|
||||||
|
babies = babies + (v.y < -.5) and 1 or 0
|
||||||
return v.y > -.5
|
return v.y > -.5
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
term.clearLine()
|
||||||
|
Util.print('%d grown, %d babies', grown, babies)
|
||||||
|
|
||||||
return #blocks
|
return #blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user