Language ActionScript
(object-oriented version)
Date: | 04/20/05 |
Author: | Unknown |
URL: | n/a |
Comments: | 0 |
Info: | n/a |
Score: | (2.96 in 24 votes) |
<code> //------------------------------------- // 99 Bottles in object oriented actionscript // 11/2002 by Ralf Bokelberg - helpQLODhelp.de //------------------------------------- //------------------------------------- // The Baseclass for the drinks //------------------------------------- function PackageClass(name, content){ this.name = name; this.content = content; } // PackageClass.prototype.display = function(nr){ if(nr > 1) return nr + " " + this.name + "s of " + this.content; else if(nr == 1) return "1 " + this.name + " of " + this.content; else return "no more " + this.name + "s of " + this.content; } //------------------------------------- // The class for bottles of beer // inherits from PackageClass //------------------------------------- function BottleOfBeerClass(){} // BottleOfBeerClass.prototype = new PackageClass("bottle", "beer"); //------------------------------------- // The WallClass to hold our bottles //------------------------------------- function WallClass(packageClass){ this.storage = []; this.packageClass = packageClass; } // WallClass.prototype.addPackages = function(count){ for(var i=0; i<count; i++){ this.storage.push(new this.packageClass()); } } // WallClass.prototype.getPackage = function(){ this.storage.pop(); return "Take one down, pass it around, "; } // WallClass.prototype.getCount = function(){ return this.storage.length; } // WallClass.prototype.display = function(){ return this.packageClass.prototype.display(this.getCount()); } // WallClass.prototype.displayLong = function(){ return this.display() + " on the wall."; } //------------------------------------- // Main //------------------------------------- wall = new WallClass(BottleOfBeerClass); wall.addPackages(5); // result = ""; do { result += wall.displayLong() + wall.display() + "\n"; result += wall.getPackage() + wall.displayLong() + "\n\n"; } while(wall.getCount() > 0); // trace(result); </code>
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
update (tippfehler!!!) | atom3000 | 01/10/06 | 5 | |
standard version | David Fichtmueller | 04/20/05 | 3 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments