CodeMonkey过关学习笔记系列:120~141关 布尔运算 AND,OR,NOT

CodeMonkey过关学习笔记系列:120-128关

•”布尔逻辑” 歌剧( BOOLEAN OPERA ) 120~135

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


CodeMonkey过关学习笔记系列:129-135关

•”布尔逻辑” 歌剧( BOOLEAN OPERA ) 120~135

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

//#这里等待 wait 熊玩耍或睡着
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


CodeMonkey过关学习笔记系列:136-141关

•”不是”我的茶( NOT MY CUP OF TEA ) 136~141

136 关挑战

//这个开始是否逻辑了。

//not 这个否定指令会把原先是 肯定yes 的结果变成 否定no 的结果。此外,它也会把原先就 否定的no 结果变成 yes 的结果.

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

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

你可能感兴趣的:(codemonkey)