CodeMonkey闯关——第二部分76-105 函数和unitl循环 清华附中

76

step distanceTo match
grab()
step distanceTo pile
drop()

77

turnTo match
step distanceTo match

grab()

turnTo pile
step distanceTo pile

drop()

78

# By the way, this is a comment line.
# It starts with a '#', like this!

for m in matches
    turnTo m
    step distanceTo m
    grab()
    # Can only grab one match at a time.
    turnTo pile
    step distanceTo pile
    drop()

79

turnTo bridge
step distanceTo bridge
turnTo match
step distanceTo match
grab()
turnTo bridge
step distanceTo bridge
turnTo pile
step distanceTo pile
drop()

80

# This is how you define a function:
goto = (a) ->
    turnTo a
    step distanceTo a

# Here we call the goto function:
goto bridge
goto match
grab()
# Add your code here:
goto bridge
goto pile
drop()

81

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

goto matches[0]
grab()
goto pile
drop()

# Add your code to get matches[1]:
goto matches[1]
grab()
goto pile
drop()

82

# Fix this function:
goto = (a) ->
    turnTo a
    step distanceTo a

# This code is ok:
for m in matches
    goto m
    grab()
    goto pile
    drop()

83

# Here the parameter name is c
# Fix this function:
goto = (c) ->
    turnTo c
    step distanceTo c
    
goto bridge
goto match
grab()
goto bridge
# Add more code here:
goto pile
drop()

84

goto = (p) ->
    # Notice that the parameter name is p
    # Write the function body here
    turnTo p
    step distanceTo p
    
# This code is OK:
for m in matches
    goto bridge
    goto m
    grab()
    goto bridge
    goto pile
    drop()

85

# Here we define a new function:
collect = (e) ->
    turnTo e
    step distanceTo e
    grab()
    # Add your code here:
    turnTo pile
    step distanceTo pile
    drop()
    
# This code is OK:
for m in matches
    collect m

86

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

# Fix this function:
collect = (e) ->
    goto e
    grab()
    goto pile
    drop()
    
# This code is OK:
for m in matches
    collect m

87

# Define goto here:
goto = (a) ->
    # Your code here
    turnTo a
    step distanceTo a

# Leave this code as is:
goto match
grab()
goto pile
drop()

88

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

# Fix this:
gotoAll = (stuff) ->
    for s in stuff
        goto s

# This code is OK:
gotoAll islands
grab()
gotoAll rafts
drop()

89

goto = (p) ->
    turnTo p
    step distanceTo p
# Fix this function:
# It should get to r, grab, then return 
# to the turtle.
getAndReturn = (r) ->
    goto r
    grab()
    goto turtle
# This code is OK:
for m in matches
    getAndReturn m
    goto pile
    drop()
    goto turtle
    turtle.step 8

90

goto = (t) ->
    turnTo t
    step distanceTo t
collect = (m) ->
    goto m
    grab()
    goto pile
    drop()
# This function should make all 
# turtles step d (d is a number).
allTurtlesStep = (d) ->
    # COMPLETE ME!
    for t in turtles
        # Your code here
        t.step d
        
# This code is OK:
allTurtlesStep 10
collect matches[0]
allTurtlesStep -10
collect matches[1]

91

until near match
    step 1
grab()
until near pile
    step 1
drop()

92

until near match
    step 3
grab()
until near pile
    step 1
drop()

93

until near match
    step 1
grab()
turnTo pile
until near pile
    step 1
drop()

94

until near match
    step 1
grab()
turnTo pile
step distanceTo pile
drop()

95

turn left
until near match
    step 1
grab()
turnTo pile
step distanceTo pile
drop()

96

until near match
    # Your code here
    step 1
grab()
turnTo pile
step distanceTo pile
drop()

97

until turtle.near bridge
    turtle.step 1
grab()
step distanceTo pile
drop()

98

until near match
    turnTo match
    step distanceTo match
    
grab()
turnTo pile
step distanceTo pile
drop()

99

chase = (m) ->
    until near m
        turnTo m
        step distanceTo m
        
chase match
grab()
chase pile
drop()

100

chase = (m) ->
    # until ....
    until near m
        # Your code here
        turnTo m
        step distanceTo m

# This code is Ok:
for m in matches
    chase m
    grab()
    chase pile
    drop()

101

goto = (t) ->
    turnTo t
    step distanceTo t
collect = (t) ->
    goto t
    grab()
    goto pile
    drop()

# Don't get there if the cat is awake!
until cat.sleeping()
    wait()

collect match

102

goto = (t) ->
    turnTo t
    step distanceTo t
collect = (t) ->
    goto t
    grab()
    goto pile
    drop()

# Use collect on each match!
for m in matches
    # Your code here
    until cat.sleeping()
        # Your code here
        wait()
    collect m

103

goto = (t) ->
    turnTo t
    step distanceTo t
# Make this function collect t 
# without getting eaten or wet.
safeCollect = (t) ->
    # Over here!
    until cat.sleeping()
        wait()
        # Your code here
    goto bridge
    goto t
    grab()
    goto bridge
    goto pile
    drop()
    
# This should work as is:
for m in matches
    safeCollect m

104

chase = (t) ->
    # Write me!
    until near t
        # Your code here
        turnTo t
        step distanceTo t

safeCollect = (m) ->
    # Complete me!
    until cat.sleeping()
        # Your code here
        wait()
    chase m
    grab()
    chase pile
    drop()
    
safeCollect match

105

# Good luck!
goto = (a) ->
    until near a
        turnTo a
        step distanceTo a
    
safeCollect = (a) ->
    until cat.sleeping()
        wait()
    goto a
    grab()
    goto pile
    drop()
    
for m in matches
    safeCollect m
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值