Language Actionscript 3
(Configurable)
| Date: | 08/06/08 |
| Author: | Jason Tye |
| URL: | n/a |
| Comments: | 6 |
| Info: | http://www.adobe.com/devnet/actionscript/ |
| Score: |
package {
import flash.display.MovieClip;
public class Beer extends MovieClip {
/* Set default song parameters: 'beer' in 'bottles' on a 'wall' */
private var bottleCount:int = 5;
private var liquid:String = 'beer';
private var container:String = 'bottle';
private var surface:String = 'wall';
/* song is comprised of 4 verses, which we loop through for each bottle */
private var verse:int = 0;
private var itVsOne:String = 'one';
private var plural:String = 's';
private var outNumber:String = bottleCount.toString();
/* song line for output */
private var songLine:String;
public function Beer() {
/* Loop through 4 times the numeber of bottles, 4 verses for each bottle */
var loopCount:int = bottleCount*4;
for (var i:int=0; i<loopCount; i++) {
sing();
}
}
/* set plural states*/
private function checkPlural(count:int):void {
if (count == 1) {
plural = '';
outNumber = 'one'
itVsOne = 'it';
} else {
outNumber = count.toString();
}
}
private function sing():String {
switch (verse) {
case 0 :
songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface;
verse++;
break;
case 1 :
songLine = outNumber+' '+container+plural+' of '+liquid;
verse++;
break;
case 2 :
songLine = 'take '+itVsOne+' down, pass it around';
verse++;
break;
case 3 :
bottleCount--;
checkPlural(bottleCount);
verse = 0;
if (bottleCount == 0) {
songLine = 'no more '+container+'s of '+liquid+' on the '+surface;
} else {
songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface;
}
break;
default :
}
return songLine;
}
}
}
Download Source | Write Comment
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
1) The song starts at 5 bottles rather than 99 (an easy fix)
2) The "Go to the store ... " verse is missing (a slightly less easy fix)
On the bright side, I like the flexibility of the program to sing about different
containers, liquids and surfaces.
don't know enough about Actionscript 3 to do one myself, but I and many others can
offer our honest opinions (from varying levels of experience) about your code's
appearance and quality. It's a level playing field, and your version could easily
work its way to the top, but only if you submit it!