Penguins

Created by Barbara Lerner

You need to download Java software in order to view this Alice world. Please visit this page: http://www.alice.org/applet/requirements/

Created with Alice, the easy-to-learn programming system. Provided free as a public service by Carnegie Mellon University


If you don't see 3d graphics on this page, click for help.

Penguins's Code

Created by:

world

Methods

  public void my_first_method ( ) {
    
       // Try jumping in the first hole
  penguin.fallInHole ( whichHole = hole2 );
  // If the penguin was not able to fit in the first hole, jump in the second hole.
  if ( ( ( penguin .distanceAbove( hole2 ) ) > -1 ) ) {
       penguin .say( I'm not in the hole );
  penguin.fallInHole ( whichHole = hole );
  } else {
    penguin .say( I am swimming! );
  }
  }


penguin

Methods

  public void fallInHole ( Object whichHole) {
    Number distanceToHole = 1 ; Number holeRadius = 1 ;
       // Walk to the edge of the hole.
  penguin .turnToFace( whichHole );
  holeRadius .set( value , ( ( ( subject = whichHole .getWidth() ) / 2 ) ) );
  distanceToHole .set( value , ( ( ( penguin .distanceTo( whichHole ) ) - holeRadius ) ) );
  penguin.walking ( x = distanceToHole );
  // Only dive in if the hole is big enough.
  if ( ( penguin .isNarrowerThan( whichHole ) ) ) {
       // Dive in the hole.
  doTogether {
       penguin.jump ( times = 1 );
  penguin .turn( FORWARD , 0.5 revolutions );
  doInOrder {
       wait( 0.5 seconds );
  penguin .moveTo( whichHole );
  }
  }
  penguin .move( UP , 5 meters ); duration = 0 seconds
  } else {
    // The hole was not big enough.
  penguin .say( Aw! No swimming today! );
  }
  }