# CodeMonkey過關學習筆記系列：特技關卡 10-1 ～ 10-8 關

``````特技關卡 10-1
for b in bananas
if not b.green()
goto bridges[1]
goto b
else
goat.goto bridges[0]
goat.goto b
``````

``````特技關卡 10-2
for b in bananas
#山羊和猴子都不可以得到所有的香蕉
#完成編碼
if b.green()
goat.goto crocodile
crocodile.turnTo b
goat.goto b
else
turtle.goto b
goto b
``````

``````特技關卡 10-3
for b in bananas
#首先，我們需要打破冰凍的香蕉
if b.frozen()
goat.goto b
goat.hit()
goat.goto turtles[1]
#現在，如果香蕉是綠色的，山羊會吃掉它
if b.green()
goat.goto b
goat.step -7
#如果不是，猴子會吃掉它
else
goto b
step -7

for t in turtles
t.step 6
``````

``````特技關卡 10-4
#確定你可以解決這個
#提示：檢查哪隻海狸可以幫助哪隻動物
#過河
beavers[1].step 5
beavers[0].step 5

for b in bananas
if b.green()
goat.goto b
else
monkey.goto b

``````

``````特技關卡 10-5
breakBanana = (banana) ->
#對冰凍的香蕉增加山羊撞擊的編碼
say "frozen"
turtles[0].goto banana
goat.hit()

eatBanana = (banana) ->
#增加山羊吃綠色香蕉的編碼
if banana.green()
turtles[0].goto banana
else
turtles[1].goto banana

for b in bananas
if b.frozen()
breakBanana(b)
eatBanana b

``````

``````

for b in bananas
if b.green()
mover = goat
else
mover = monkey
say mover
mover.goto b``````

``````特技關卡 10-7
mover = monkey
for b in bananas
if b.green()
x = 5
mover = goat
else
x = 10
mover = monkey
mover.step x
``````

``````特技關卡 10-8
#如果x>0，那麼烏龜前進
#如果x<0，那麼烏龜後退

x = 12
for b in bananas
if b.green()
turtle.step -x
goat.goto turtle
turtle.step 2*x
goat.goto b
else
monkey.goto turtle
turtle.step -2*x
monkey.goto b
``````