topical media & game development
actionscript-zoo-lib-Apple.ax
actionscript-zoo-lib-Apple.ax
[swf]
flex
package {
// The @ax-actionscript-zoo-lib-Apple class represents one of the types of food a pet can eat
public class @ax-actionscript-zoo-lib-Apple extends actionscript_zoo_lib_Food {
// The amount of calories in an @ax-actionscript-zoo-lib-Apple object, if no specific
// amount is indicated
private static var DEFAULT_CALORIES:int = 100;
// Tracks whether an @ax-actionscript-zoo-lib-Apple object has a worm
private var wormIn@ax-actionscript-zoo-lib-Apple:Boolean;
// Constructor
public function @ax-actionscript-zoo-lib-Apple (initialCalories:int = 0) {
// If no valid calorie amount is specified...
if (initialCalories <= 0) {
// ...give this @ax-actionscript-zoo-lib-Apple object the default amount
initialCalories = @ax-actionscript-zoo-lib-Apple.DEFAULT_CALORIES;
}
// Invoke the Food class constructor
super(initialCalories);
// Randomly determine whether this @ax-actionscript-zoo-lib-Apple object as a worm (50% chance)
wormIn@ax-actionscript-zoo-lib-Apple = Math.random() >= .5;
// Give this food item a name
setName("@ax-actionscript-zoo-lib-Apple");
}
// Returns a Boolean indicating whether the @ax-actionscript-zoo-lib-Apple object has a worm
public function hasWorm ():Boolean {
return wormIn@ax-actionscript-zoo-lib-Apple;
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.