特技关卡 5-1
turtles[0].step 6
turtles[2].step -8
turtles[1].step 6+6
step 19
特技关卡 5-2
step 6
turtles[2].step 20
step 6
turtles[1].step 8
step 6
turtles[0].step -12
特技关卡 5-3
turtle.turnTo bananas[0]
turtle.step 9
turtle.turnTo bananas[1]
turtle.step 19
turtle.turnTo bananas[2]
turtle.step 19
turtle.turnTo bananas[0]
turtle.step distanceTo bananas[0]
turtle.turnTo bananas[1]
turtle.step distanceTo bananas[1]
turtle.turnTo bananas[2]
turtle.step distanceTo bananas[2]
i = 0
3.times ->
turtle.turnTo bananas[i]
turtle.step distanceTo bananas[i]
i++
for b in bananas
turtle.turnTo b
turtle.step distanceTo b
特技关卡 5-4
turnTo bananas[4]
step distanceTo bananas[4]
turnTo bananas[7]
step distanceTo bananas[7]
turnTo bananas[10]
step distanceTo bananas[10]
turnTo bananas[7*2]
step distanceTo bananas[7*2]
特技关卡 5-5
step 15
beavers[1].step 15
beavers[0].step -15
turn left
step 15
turn left
step 15
特技关卡 5-6
x=0
4.times ->
beavers[x].step 2.5*(x+1)
x += 1
step distanceTo banana
特技关卡 5-7
beavers[0].step 5
beavers[1].step 10
beavers[2].step 10
step distanceTo banana
特技关卡 5-8
x = 0
7.times ->
turnTo bananas[x]
step distanceTo bananas[x]
x = x+1
特技关卡 5-9
crocodiles[2].turn left
crocodiles[0].turn -45
step 9
turn left
step 9
turn right
step 9
特技关卡 5-10
goats[0].step 3
goats[0].hit()
goats[0].step -11
goats[0].hit()
goats[1].step 14
goats[1].hit()
goats[1].step -18
goats[1].hit()
4.times ->
step 20
turn right
goto = (o, t) ->
o.turnTo(t)
o.step(o.distanceTo(t))
hitB = (goat, banana) ->
goto(goat, banana)
goat.hit()
hitB(goats[1], bananas[0])
hitB(goats[0], bananas[1])
hitB(goats[0], bananas[2])
hitB(goats[1], bananas[3])
3.times ->
monkey.step 20
monkey.turn right
turnStepHit = (goat, banana) ->
goat.turnTo banana
goat.step goat.distanceTo banana
goat.hit()
turnStepHit(goats[0], bananas[1])
turnStepHit(goats[0], bananas[2])
turnStepHit(goats[1], bananas[0])
turnStepHit(goats[1], bananas[3])
4.times ->
step 20
turn right
goats[1].turnTo bananas[0]
goats[1].step(goats[1].distanceTo bananas[0])
goats[1].hit()
monkey.step(monkey.distanceTo bananas[0])
monkey.turnTo bananas[1]
goats[0].turnTo bananas[1]
goats[0].step(goats[0].distanceTo bananas[1])
goats[0].hit()
monkey.step(monkey.distanceTo bananas[1])
monkey.turnTo bananas[2]
goats[0].turnTo bananas[2]
goats[0].step(goats[0].distanceTo bananas[2])
goats[0].hit()
monkey.step(monkey.distanceTo bananas[2])
monkey.turnTo bananas[3]
goats[1].turnTo bananas[3]
goats[1].step(goats[1].distanceTo bananas[3])
goats[1].hit()
monkey.step(monkey.distanceTo bananas[3])
eatBananas = (monkey, goat, banana, next) ->
goat.turnTo(banana)
goat.step(goat.distanceTo(banana))
goat.hit()
monkey.step(monkey.distanceTo(banana))
monkey.turnTo(next)
eatBananas(monkey, goats[1], bananas[0], bananas[1])
eatBananas(monkey, goats[0], bananas[1], bananas[2])
eatBananas(monkey, goats[0], bananas[2], bananas[3])
eatBananas(monkey, goats[1], bananas[3], bananas[0])
eatBananas = (banana, next, goat) ->
goat.turnTo(banana)
goat.step(goat.distanceTo(banana))
goat.hit()
step(distanceTo(banana))
turnTo(next)
eatBananas(bananas[0], bananas[1],goats[1]) # 第一个参数顺序很重要
eatBananas(bananas[1], bananas[2],goats[0])
eatBananas(bananas[2], bananas[3],goats[0])
eatBananas(bananas[3], bananas[0],goats[1])
eatBananas = (banana, goat) ->
goat.turnTo(banana)
goat.step(goat.distanceTo(banana))
goat.hit()
turnTo(banana)
step(distanceTo(banana))
eatBananas(bananas[0], goats[1])
eatBananas(bananas[1], goats[0])
eatBananas(bananas[2], goats[0])
eatBananas(bananas[3], goats[1])
goto = (o, t) ->
o.turnTo(t)
o.step(o.distanceTo(t))
eatBananas = (banana, goat) ->
goto(goat, banana)
goat.hit()
goto(monkey, banana)
eatBananas(bananas[0], goats[1])
eatBananas(bananas[1], goats[0])
eatBananas(bananas[2], goats[0])
eatBananas(bananas[3], goats[1])