1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| 特技关卡 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
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
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])
|