CodeMonkey闯关——第三部分146-175 清华附中

146

if not banana.green()
    #你只能修改这里的代码:
    goto banana

147

for b in bananas
    turnTo b
    if b.rotten()
        say "Yuck!"
    else
        goto b

148

goto bush
goto bananas[0]

149

if not banana.rotten()
    goto banana

150

for b in bananas
    #修复这里的代码:
    if  not b.rotten()
        goto b

151

for b in bananas
    # Your code here
    if not b.rotten()
        # Your code here
        goto b
    else
        goto bush

152

goto banana

153

for b in bananas
    # Your code here
    goto b

154

if health() == 40 #40不等于100,所以判断结果是no
    goto banana

155

goto healthZone
#修改这里,健康度永远到不到100。
until health() == 100
    wait()
goto banana

156

for b in bananas
    goto healthZone
    #在这里等待,直到小猴的健康度恢复到100。
    until health() == 100
        # Your code here
        wait()
    goto b

157

goto healthZone
until health() == 100
    # Your code here
    wait()
goto banana

158

if health() < 90 #80小于90,所以判断结果是yes
    goto banana

159

for b in bananas
    goto b
    #提示: 如果健康度低于70,就需要去休息区恢复啦
    if health() < 70
        # Your code here
        goto healthZone
        until health() == 100
            # Your code here
            wait()

160

#这个函数是有用的:
gotoNearestHealth = () ->
    d0 = distanceTo healthZones[0]
    d1 = distanceTo healthZones[1]
    if d0 < d1
        goto healthZones[0]
    else
        goto healthZones[1]
    
for b in bananas
    goto b
    if health() < 60
        gotoNearestHealth() 
        #在这里等待,直到小猴恢复健康!
        until health() == 100
            # Your code here
            wait()

161

example = () ->
    return not banana.rotten()
    
if example() #example()返回的值是no
    goto banana
else
    turn 360

162

yummy = (x) ->
    return not x.rotten()

#修复这里吧:
for b in bananas
     #这里调用了yummy函数来判断 b 是不是美味的
    if yummy b
        goto b

163

healthy = () ->
    return health() == 100


goto healthZone

#在这里使用healthy()函数
until healthy()
    # Your code here
    wait()

goto banana

164

healthy = () ->
    return health() == 100

injured = () ->
    return health() <= 80

#在这里使用healthy()和injured()两个条件进行判断:
for b in bananas
    # Your code here
    if injured()
        # Your code here
        goto healthZone
        until healthy()
            # Your code here
            wait()
    goto b

165

healthy = () ->
    #修复这里吧
    return health() > 80

#如果你已经修复了 healthy() 函数,这里就应该是正常的。
goto healthZone
until healthy()
    wait()
goto bush
goto banana

166

safeFrom = (a) ->
    return a.sleeping() or a.playing()#是不是要用 or 判断?

#另一种调用包含参数的函数的用法
#是使用'()':
until safeFrom(tiger)
    wait()

goto banana

167

safeFrom = (a) ->
    return a.sleeping() or a.playing() #修复这里吧


#这段代码是正常的:
until safeFrom(tiger) and safeFrom(bear)
    wait()

goto banana

168

negative = () ->
    return no #请把第一个yes改成no。

positive = () ->
    return yes #这段代码是正常的
    
if negative()
    goto bananas[0]
if positive()
    goto bananas[1]

169

foo = () ->
    return yes

    
if foo()
    goto banana
else
    say "nope"

170

until not crow.watching()
    say "Boo!"
goto banana

171

safe = () ->
    return not crow.watching()
    
#使用say来吓走乌鸦吧!
    
until safe()
    # Your code here
    say "Y"
goto banana

172

safe = () ->
    return not crows[0].watching() and not crows[1].watching()
    
#在这里调用 safe()函数
until safe()
    say "Hello world!"
    # Your code here
goto banana

173

safe = () ->
    #完成这段代码吧
    #只有在没有乌鸦监视的时候,才返回yes。
    return not crows[0].watching() and not crows[1].watching()

until safe()
    say "Go away!"

for b in bananas
    goto b

174

safe = () ->
    #修复这里:
    return not crows[0].watching() and not crows[1].watching() and not crows[2].watching()

until safe()
    say "Go away!"

goto banana

175

safe = () ->
    for c in crows
        if c.watching()
            #修复这里:
            return no #这样是安全的吗?
    #如果到达这里意味着
    #没有乌鸦在监视啦
    return yes

#这段代码是正常的:
until safe()
    say "Go away!"

goto banana
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值