Fish_and_Gumdrops

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.

Fish_and_Gumdrops's Code

Created by:

world

Methods

  world.my first method ( )
    distanceToGumdrop = 1 , distanceToGumdrop2 = 1
       // Determine how far the fish is from each gumdrop.
  distanceToGumdrop set value to ( fishy distance to gumdrop )
  distanceToGumdrop2 set value to ( fishy distance to gumdrop2 )
  // Have the fish eat the closer gumdrop.
  If ( distanceToGumdrop > distanceToGumdrop2 )
       fishy.eatGumdrop whichGumdrop = gumdrop2
  Else
    fishy.eatGumdrop whichGumdrop = gumdrop


fishy

Methods

  fishy.eatGumdrop ( [Obj] whichGumdrop)
    No variables
       // Swim to the gumdrop.
  fishy turn to face whichGumdrop
  fishy move to whichGumdrop
  // Make the gumdrop disappear to give the illusion of being eaten.
  whichGumdrop set opacity to 0 (0%) duration = 0 seconds
  // If the fish ate a red gumdrop, it doubles in size. If it ate a yellow gumdrop, it gets smaller.
  If ( whichGumdrop . color == (1, 0, 0) )
       fishy resize 2
  Else
    fishy resize 0.5