CodeMonkey過關學習筆記系列:86-95關
•“直到”沙地 ( THE SANDS OF UNTIL )86~100
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZlBnaugTZnFWbp9CX5V2au9WblR2bj9CXyVGdzFWbvw1ZvxmY512LcNkRTV2Zh12Lc12bj5CduVGdu92YyV2c1JWdoRXan5ydhJ3Lc9CX6MHc0RHaiojIsJye.jpeg)
第 關挑戰
//"直到"沙地
//接下來要介紹的是 直到 until 這個循環指令 !
//這個和71關是一樣的。這裡用到了until和near。
until near match
step
grab()
until near pile
step
drop()
第 關挑戰
//接近 near 這個指令會傳回給你 - 肯定的 yes 或 否定的 no 的結果
//這個和71,86關是一樣的。這裡用到了until和near。
until near match
step
grab()
until near pile
step
drop()
第 關挑戰
//如果你不好好使用的話 , 直到 until 這個循環指令将會永無止盡的繼續下去.
//介紹了死循環
until near match
step
grab()
turnTo pile
until near pile
step
drop()
第 關挑戰
接下來你需要好好利用 直到 until 這個循環指令哦.
until near match
step
grab()
turnTo pile
step distanceTo pile
drop()
第 關挑戰
turn left
until near match
step
grab()
turnTo pile
step distanceTo pile
drop()
第 關挑戰
until near match
step
grab()
turnTo pile
step distanceTo pile
drop()
第 關挑戰
until turtle.near bridge
turtle.step
grab()
step distanceTo pile
drop()
第 關挑戰
until near match
turnTo match
step
grab()
turnTo pile
step distanceTo pile
drop()
第 關挑戰
希望你沒有忘了函數,也就是 functions !
chase = (m) ->
until near m
turnTo m
step
chase match
grab()
chase pile
drop()
第 關挑戰
chase = (m) ->
until near m
turnTo m
step
#這段代碼是正常的:
for m in matches
chase m
grab()
chase pile
drop()
CodeMonkey過關學習筆記系列:96-100關
•“直到”沙地 ( THE SANDS OF UNTIL )86~100
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZlBnaugTZnFWbp9CX5V2au9WblR2bj9CXyVGdzFWbvw1ZvxmY512LcNkRTV2Zh12Lc12bj5CduVGdu92YyV2c1JWdoRXan5ydhJ3Lc9CX6MHc0RHaiojIsJye.jpeg)
第 關挑戰
goto = (t) ->
turnTo t
step distanceTo t
collect = (t) ->
goto t
grab()
goto pile
drop()
#如果貓還醒着,千萬别走過去!
until cat.sleeping()
wait()
collect match
step
第 關挑戰
用 wait 指令來靜待貓咪睡覺吧...
goto = (t) ->
turnTo t
step distanceTo t
collect = (t) ->
goto t
grab()
goto pile
drop()
for m in matches
until cat.sleeping()
wait()
collect m
第 關挑戰
goto = (t) ->
turnTo t
step distanceTo t
#讓這個函數能夠收集t collect t
#并且不要被吃掉或掉到水裡哦
safeCollect = (t) ->
until cat.sleeping()
wait()
#就在那兒!
goto bridge
goto t
grab()
goto bridge
goto pile
drop()
for m in matches
safeCollect m
第 關挑戰
chase = (t) ->
#實作這裡!
turnTo t
step distanceTo t
safeCollect = (m) ->
until cat.sleeping()
wait()
#完成這裡!
until near m
chase m
grab()
chase pile
drop()
safeCollect match
第 關挑戰
chase = (t) ->
turnTo t
step distanceTo t
safeCollect = (m) ->
until cat.sleeping()
wait()
until near m
chase m
grab()
chase pile
drop()
for m in matches
safeCollect m