WITH Spider;
PROCEDURE Drunken_Spider IS
----------------------------------------------------------------
--| Spider tries to tour its room but has drunk too much, so
--| takes a random number of steps and may hit the wall. If the
--| spider hits the wall, it turns around and keeps going.
--| Author: M. B. Feldman, The George Washington University
--| Last Modified: July 1998
----------------------------------------------------------------

BEGIN -- Drunken_Spider

  Spider.Start;

  LOOP                     -- keep going forever

    Spider.Face(WhichWay => Spider.RandomDirection);
    Spider.ChangeColor(NewColor => Spider.RandomColor);

    -- Spider will count steps correctly
    -- but might change direction
    FOR Count IN 1..Spider.RandomStep LOOP

      IF Spider.AtWall THEN
        Spider.TurnRight;
        Spider.TurnRight;
      END IF;

      Spider.Step;

    END LOOP;

    Spider.TurnRight;

  END LOOP;

END Drunken_Spider;