第 25 关挑战
//你可以修正这个循环 loop 的错误吗 ?4.times ->
turn left
step 5
turn right
step 5//解法:
s = 20
For I in [1..11]
step s
turn left
if I % 3 == 0
s -= 5//另外的解法:
s=20
I=111.times ->
step s
turn left
if I % 3 == 0
s -= 5
I++
//另外的解法:2.times ->
turn 45
step 30
step -30
turn -45
step -5//另外的解法:2.times ->
turn 45
step 28
turn 135
step 5
第 26 关挑战
step 53.times ->
turtle.step 10
turtle.turn right
第 27 关挑战
4.times ->
step 10
step -10
turn right
第 28 关挑战
10.times ->
step 3
turn 18
step 10
第 29 关挑战
turtle.step 5
step 33.times ->
turtle.step 10
turtle.turn left
turn left
step 5
第 75 关挑战
# 这里开始引入函数的概念了,这一关卡是不是和上一个很类似
goto = (t) ->
turnTo t
step distanceTo t
goto bridge
goto match
grab()
goto bridge
goto pile
drop()
第 76 关挑战
goto = (a) ->
turnTo a
step distanceTo a
for match in matches
goto match
grab()
goto pile
drop()
//================================================
goto = (a) ->
turnTo a
step distanceTo a
goto matches[0]
grab()
goto pile
drop()
goto matches[1]
grab()
goto pile
drop()
第 77 关挑战
goto = (a) ->
turnTo a
step distanceTo a
for m in matches
goto m
grab()
goto pile
drop()
第 78 关挑战
goto = (c) ->
turnTo c
step distanceTo c
goto bridge
goto match
grab()
goto bridge
goto(pile)
drop()
第 79 关挑战
goto = (p) ->
#请在这里编写函数的实现
turnTo p
step distanceTo p
for m in matches
goto bridge
goto m
grab()
goto bridge
goto pile
drop()
第 80 关挑战
collect = (e) ->
turnTo e
step distanceTo e
grab()
turnTo pile
step distanceTo pile
drop()
for m in matches
collect m
第 81 关挑战
这里不只有一个函数, 而是有 两个 函数 !
goto = (t) ->
turnTo t
step distanceTo t
collect = (e) ->
goto e
grab()
goto pile
drop()
for m in matches
collect m
第 82 关挑战
#请在这里定义 goto 函数
goto = (x)->
turnTo x
step distanceTo x
goto match
grab()
goto pile
drop()
第 83 关挑战
接下来我们试试将小岛 islands 和木筏 rafts 作为函数的参数来使用
goto = (t) ->
turnTo t
step distanceTo t
gotoAll = (stuff) ->
for s in stuff
goto s
gotoAll islands
grab()
gotoAll rafts
drop()
第 84 关挑战
goto = (t) ->
turnTo t
step distanceTo t
getAndReturn = (r) ->
goto r
grab()
goto turtle
for m in matches
getAndReturn m
goto pile
drop()
goto turtle
turtle.step 8
第 85 关挑战
我们也可以用数字 numbers 作为函数的参数
goto = (t) ->
turnTo t
step distanceTo t
collect = (m) ->
goto m
grab()
goto pile
drop()
#这个函数应该让所有
#turtles 前进 d (d是数字)
allTurtlesStep = (d) ->
#请完成这里!
for c in turtles
c.step d
allTurtlesStep 10
collect matches[0]
allTurtlesStep -10
collect matches[1]
第 86 关挑战
//"直到"沙地//接下来要介绍的是 直到 until 这个循环指令 !//这个和71关是一样的。这里用到了until和near。
until near match
step 1
grab()
until near pile
step 1
drop()
第 87 关挑战
//接近 near 这个指令会返回给你 - 肯定的 yes 或 否定的 no 的结果//这个和71,86关是一样的。这里用到了until和near。
until near match
step 1
grab()
until near pile
step 1
drop()
第 88 关挑战
//如果你不好好使用的话 , 直到 until 这个循环指令将会永无止尽的继续下去.//介绍了死循环
until near match
step 1
grab()
turnTo pile
until near pile
step 1
drop()
第 89 关挑战
接下来你需要好好利用 直到 until 这个循环指令哦.
until near match
step 1
grab()
turnTo pile
step distanceTo pile
drop()
第 90 关挑战
turn left
until near match
step 1
grab()
turnTo pile
step distanceTo pile
drop()
第 91 关挑战
until near match
step 1
grab()
turnTo pile
step distanceTo pile
drop()
第 93 关挑战
until near match
turnTo match
step 1
grab()
turnTo pile
step distanceTo pile
drop()
第 94 关挑战
希望你没有忘了函数,也就是 functions !
chase = (m) ->
until near m
turnTo m
step 1
chase match
grab()
chase pile
drop()
第 95 关挑战
chase = (m) ->
until near m
turnTo m
step 1
#这段代码是正常的:
for m in matches
chase m
grab()
chase pile
drop()
第 96 关挑战
goto = (t) ->
turnTo t
step distanceTo t
collect = (t) ->
goto t
grab()
goto pile
drop()
#如果猫还醒着,千万别走过去!
until cat.sleeping()
wait()
collect match
step 15
第 97 关挑战
用 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
第 98 关挑战
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
第 99 关挑战
chase = (t) ->
#实现这里!
turnTo t
step distanceTo t
safeCollect = (m) ->
until cat.sleeping()
wait()
#完成这里!
until near m
chase m
grab()
chase pile
drop()
safeCollect match
第 100 关挑战
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
第 101 关挑战
goto bridge
goto banana
第 102 关挑战
goat.hit()goto banana
第 103 关挑战
goat.hit(banana)
goto banana
第 104 关挑战
#goat.hit()
goat.turn right
goat.hit()
step 20
第 105 关挑战
goat.goto bananas[0]
goat.hit()
goat.goto bananas[2]
goat.hit()
for b in bananas
goto b
第 106 关挑战
请试试看 冷冻的香蕉banana.frozen() 这个指令.
say banana.frozen()
goat.hit()
say banana.frozen()
goto banana
第 107 关挑战
请使用 如果 if 指令来判断条件是否成立 !
if banana.frozen()
goat.hit()
goto banana
第 108 关挑战
有的时候,你写在 如果 if 指令里面的判断条件并不会真的发生.
if banana.frozen()
goat.goto banana
goat.hit()
goto banana
第 109 关挑战
你可以在一个 for循环中使用 如果 if 条件判断
for b in bananas
if b.frozen()
goat.goto b
goat.hit b
goto b
第 110 关挑战
#在 loop 循环中使用 iffor b in bananas
if b.frozen()
goat.goto(b)
goat.hit(b)
monkey.goto b
第 111 关挑战
for b in bananas
if b.frozen()
goat.hit(b)
monkey.goto b
turtle.step 5
第 112 关挑战
goat.goto banana
第 113 关挑战
goat.step 15
monkey.step 15
第 114 关挑战
if banana.green()
goat.goto banana
第 115 关挑战
if banana.green()
say "It's green!"else
monkey.goto(banana)
第 116 关挑战
for b in bananas
if b.green()
goat.goto b
else
monkey.goto b
第 117 关挑战
不管是哪种颜色的香蕉,所有的 结冰香蕉都应该使用 撞击 hit() 指令来去冰, 但是只有山羊会吃掉 绿色的香蕉.
for b in bananas
goat.goto b
goat.hit()
if b.green()
goat.goto b
else
monkey.goto b
第 118 关挑战
for b in bananas
if b.green()
goat.goto b
else
monkey.goto b
第 119 关挑战
breakBanana = (f) ->
if f.frozen()
goat.goto f
goat.hit f
if f.green()
goat.goto f
else
monkey.goto f
for b in bananas
breakBanana b
第 120 关挑战
until tiger.sleeping()
wait()
goto banana
第 121 关挑战
until bear.sleeping()
wait()
goto banana
第 122 关挑战
for b in bananas
until bear.sleeping()
wait() //#等待,什么?
goto b
第 123 关挑战
until bear.sleeping() and tiger.sleeping()
wait()
goto banana
第 124 关挑战
until bear.sleeping() and tiger.sleeping()
wait()
goto banana
第 125 关挑战
until bear.sleeping() and tiger.sleeping() //#并且...
wait()
for b in bananas
goto b
第 126 关挑战
for b in bananas
until bear.sleeping() and tiger.sleeping() //#并且...
wait()
if b.green()
goat.goto b
monkey.goto b
第 127 关挑战
waitForSafety = () ->
until bear.sleeping() and tiger.sleeping()
wait()
for b in bananas
waitForSafety()
goto b
第 128 关挑战
for b in bananas
until bear.sleeping() and tiger.sleeping()
wait()
if b.frozen()
goat.goto b
goat.hit()
until bear.sleeping() and tiger.sleeping()
wait()
monkey.goto b
第 129 关挑战
until tiger.sleeping() or tiger.playing()
wait()
goto banana
第 130 关挑战
或者 or 指令能够让小猴等到许多个判断式其中之一的条件成立了之后,就开始下个行动.
until tiger.sleeping() or tiger.playing()
wait()
goto banana
第 131 关挑战
//你可以在所有的判断式里面都使用 或者 or 指令
until tiger.sleeping() or tiger.playing()
wait()
step 10//#这里等待 <code>wait</code> 熊玩耍或睡着
until bear.sleeping() or bear.playing()
wait()
step 10
第 132 关挑战
until bear.playing() or bear.sleeping()
wait()
goat.goto banana
第 133 关挑战
for b in bananas
until tiger.playing() or tiger.sleeping()
wait()
if b.green()
goat.goto b
else
monkey.goto b
第 134 关挑战
for b in bears
until b.sleeping() or b.playing()
wait()
step 10
第 135 关挑战
waitFor = (t) ->
until t.sleeping() or t.playing()
wait()
for t in tigers
for stepper in [monkey, goat]
waitFor t
stepper.step 10
第 137 关挑战
请试试看使用 烂掉的 rotten() 来识别烂掉的香蕉并且不要靠近它们!
rotten英 [ˈrɒtn] 美 [ˈrɑ:tn] adj.腐烂的;恶臭的;堕落的;极坏的
for b in bananas
turnTo b
if b.rotten()
say "Yuck!"else
goto b
第 138 关挑战
goto bush
goto bananas[0]
第 139 关挑战
if not banana.rotten()
goto banana
第 140 关挑战
for b in bananas
#修复这里的条件:
if not b.rotten()
goto b
第 141 关挑战
for b in bananas
if not b.rotten()
goto b
goto bush
第 142 关挑战
say health()
goto banana
第 143 关挑战
goto bananas[0]
goto bananas[1]
第 144 关挑战
if health() == 40//#是的,40等于40,得到yes
goto banana
if health() == 100//#不是,40不是100,得到no
goto banana
第 160 关挑战
until not crow.watching()
say "Boo!"
goto banana
第 161 关挑战
//请使用 说话 say 这个指令,直到安全为止.
safe = () ->
return not crow.watching()
//#使用 say 函数来吓走乌鸦 crow 吧
until safe()
say "x"
goto banana
第 162 关挑战
safe = () ->
if crows[0].watching()
return no
if crows[1].watching()
return no
#如果到达这里意味着两只乌鸦都没有在监控啦
return yes
#在这里使用 safe() 函数
goto banana
或者
safe = () ->
if crows[0].watching() or crows[1].watching() //0号或者1号乌鸦在监视,就是不安全的情况return no
return yes
第 163 关挑战
safe = () ->
#只有乌鸦监控的时候才返回 yes
return not( crows[1].watching() or crows[0].watching())
until safe()
say "Go away!"for b in bananas
goto b
第 164 关挑战
safe = () ->
return (not crows[0].watching() and not crows[1].watching() and not crows[2].watching())
或者
return not (crows[0].watching() or crows[1].watching() or crows[2].watching())
until safe()
say "Go away!"
goto banana
第 165 关挑战
safe = () ->
for c in crows
if c.watching()
return no //#这样是安全的吗?//#如果到达这里意味着没有乌鸦在监控啦return yes
until safe()
say "Go away!"
goto banana