// Lyn's Recursion Examples // CS111 , 3/18/98 import java.awt.*; public class RecursionWorld extends BuggleWorld { public void run () { Recurser rita = new Recurser(); rita.trail(4); } } class Recurser extends Buggle { public void trail (int n) { if (n == 0) { // Do nothing } else { dropBagel(); forward(); trail(n - 1); } } public void trailAndBack (int n) { if (n == 0) { // Do nothing } else { dropBagel(); forward(); trailAndBack(n - 1); backward(); } } public void trailOrStop (int n) { if (n == 0) { // Do nothing } else if (isFacingWall()) { dropBagel(); } else { dropBagel(); forward(); trailOrStop(n - 1); } } public void trailOrStopAndBack (int n) { if (n == 0) { // Do nothing } else if (isFacingWall()) { dropBagel(); } else { dropBagel(); forward(); trailOrStopAndBack(n - 1); backward(); } } public void trailToWall () { if (isFacingWall()) { dropBagel(); } else { dropBagel(); forward(); trailToWall(); } } public void trailToWallAndBack () { if (isFacingWall()) { dropBagel(); } else { dropBagel(); forward(); trailToWallAndBack(); backward(); } } }