Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y, z = 0, 0, 0
- local f = 0
- local limite = 5
- print("Iniciando modo aleatorio...")
- print("Raio limite: " .. limite .. " blocos.")
- while true do
- -- Checagem de CombustÃvel!
- if turtle.getFuelLevel() == 0 then
- print("Alerta: Acabou o combustivel! Coloque carvao e digite 'refuel all'.")
- break -- Para o programa
- end
- local acao = math.random(1, 5)
- if acao == 1 then
- local nx, nz = x, z
- if f == 0 then nz = nz + 1
- elseif f == 1 then nx = nx + 1
- elseif f == 2 then nz = nz - 1
- elseif f == 3 then nx = nx - 1
- end
- if math.abs(nx) <= limite and math.abs(nz) <= limite then
- if turtle.forward() then
- x, z = nx, nz
- end
- else
- turtle.turnRight()
- f = (f + 1) % 4
- end
- elseif acao == 2 then
- if y + 1 <= limite then
- if turtle.up() then
- y = y + 1
- end
- end
- elseif acao == 3 then
- if y - 1 >= -limite then
- if turtle.down() then
- y = y - 1
- end
- end
- elseif acao == 4 then
- turtle.turnRight()
- f = (f + 1) % 4
- elseif acao == 5 then
- turtle.turnLeft()
- f = (f - 1) % 4
- if f < 0 then f = 3 end
- end
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment