CodeMonkey过关学习笔记系列:76-85关

CodeMonkey过关学习笔记系列:76-85关

image93.jpeg

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()

image94.jpeg

77 关挑战

goto = (a) ->
    turnTo a
    step distanceTo a

for m in matches
    goto m
    grab()
    goto pile
    drop()

image95.jpeg

78 关挑战

goto = (c) ->
    turnTo c
    step distanceTo c

goto bridge
goto match
grab()
goto bridge

goto(pile)
drop()


image96.jpeg

79 关挑战

goto = (p) ->
    #请在这里编写函数的实现
    turnTo p
    step distanceTo p

for m in matches
    goto bridge
    goto m
    grab()
    goto bridge
    goto pile
    drop()

image97.jpeg

80 关挑战

collect = (e) ->
    turnTo e
    step distanceTo e
    grab()
    turnTo pile
    step distanceTo pile
    drop()
for m in matches
    collect m

image98.jpeg

81 关挑战

这里不只有一个函数, 而是有 两个 函数 !
goto = (t) ->
    turnTo t
    step distanceTo t

collect = (e) ->
    goto e
    grab()
    goto pile
    drop()

for m in matches
    collect m


image99.jpeg

82 关挑战

#请在这里定义 goto 函数
goto = (x)->
    turnTo x
    step distanceTo x

goto match
grab()
goto pile
drop()

image100.jpeg

83 关挑战

接下来我们试试将小岛 islands 和木筏 rafts 作为函数的参数来使用

goto = (t) ->
    turnTo t
    step distanceTo t
gotoAll = (stuff) ->
    for s in stuff
        goto s

gotoAll islands
grab()
gotoAll rafts
drop()

image101.jpeg

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

image102.jpeg

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]

猜你喜欢

转载自blog.csdn.net/mmh19891113/article/details/80748276