code complete

here's the final Tamagotchi class code

class Tamagotchi { private var currentCalories:Number; private var name:String; private var isAlive:Boolean; private var digestIntervalID:Number; private var clip:MovieClip; private static var MAX_NAME_LENGTH:Number = 20; private static var DEFAULT_NAME:String = "Unnamed Pet"; private static var MAX_CALORIES:Number = 2000; private static var CALORIES_PER_SECOND:Number = 100; private static var SYMBOL_ID:String = "TamagotchiSymbol"; public function Tamagotchi (petName:String, target:MovieClip, depth:Number, x:Number, y:Number) { clip = target.attachMovie(Tamagotchi.SYMBOL_ID, "tamagotchi" + depth, depth); clip._x = x; clip._y = y; setName(petName); currentCalories = Tamagotchi.MAX_CALORIES; isAlive = true; digestIntervalID = setInterval(this, "digest", 1000); Key.addListener(this); } public function feed (foodItem:Food):Void { if (isAlive == false) { trace(getName() + " is dead. You can't feed it."); return; } trace(getName() + " ate the " + foodItem.getName() + " (" + foodItem.getCalories() + " calories)."); if (foodItem.getCalories() + currentCalories > Tamagotchi.MAX_CALORIES) { currentCalories = Tamagotchi.MAX_CALORIES; } else { currentCalories += foodItem.getCalories(); } } public function setName (newName:String):Void { if (newName.length > Tamagotchi.MAX_NAME_LENGTH) { trace("Warning: specified name is too long."); newName = newName.substr(0, Tamagotchi.MAX_NAME_LENGTH); } else if (newName == "") { trace("Warning: specified name is too short."); return; } name = newName; clip.name_txt.text = name; } public function getName ():String { if (name == null) { return Tamagotchi.DEFAULT_NAME; } else { return name; } } private function die (deathType:Number):Void { clearInterval(digestIntervalID); isAlive = false; Key.addListener(this); trace(getName() + " has died."); clip.gotoAndStop("dead"); } private function displayHealthStatus ():Void { var caloriePercentage:Number = Math.floor((currentCalories /Tamagotchi.MAX_CALORIES)*100); trace(getName() + " has " + currentCalories + " calories" + " (" + caloriePercentage + "% of its food) remaining."); if (caloriePercentage < 20) { clip.hungerIcon.gotoAndStop("starving"); } else if (caloriePercentage < 50) { clip.hungerIcon.gotoAndStop("hungry"); } else { clip.hungerIcon.gotoAndStop("full"); } } private function digest ():Void { trace("The Tamagotchi is digesting..."); currentCalories -= Tamagotchi.CALORIES_PER_SECOND; if (currentCalories <= 0) { die(); } else { displayHealthStatus(); } } private function onKeyDown ():Void { if (Key.getCode() == 65) { feed(new Apple()); } else if (Key.getCode() == 83) { feed(new Sushi()); } } }