DAY 27
1
Software Development

## Day27 小烏龜動工的基本指令集

/rom/programs/turtle/ 以及 /rom/apis/turtle/

### 小烏龜轉向和移動

go left
go right
go left 3
go right 2

/rom/programs/turtle/turn.lua

turn left
turn right
turn left 3
turn right 2

go up
go down
go forward
go back

### 為小烏龜補充燃料

refuel
refuel 3
refuel all

refuel all 就是補充小烏龜儲物箱裡面所有可以當作燃料的東西

turtle.getFuelLevel()

### 小烏龜連續轉向或移動

go left back back top

go right 2 forward 3 down

local sDirection = tArgs[nArg]
local nDistance = 1
if nArg < #tArgs then
local num = tonumber(tArgs[nArg + 1])
if num then
nDistance = num
nArg = nArg + 1
end
end
nArg = nArg + 1

### 讓小烏龜跳舞

CC: Tweaked 提供了一支給小烏龜手舞足蹈的程式，雖然我有點看不懂這樂趣 XD

dance 最後的 parallel.waitForAny 模擬多執行緒

parallel.waitForAny(
function() os.pullEvent("key") end,
function()
while true do
tMoves[math.random(1, #tMoves)]()
end
end
)

### 為小烏龜換裝備

/rom/programs/turtle/equip.lua 和 /rom/programs/turtle/unequip.lua

local nSlot = tonumber(tArgs[1])
local sSide = tArgs[2]
if sSide == "left" then
equip(nSlot, turtle.equipLeft)
elseif sSide == "right" then
equip(nSlot, turtle.equipRight)
else
printUsage()
return
end