function Die( stars )
{
this.stars = stars;
this.red = 0;
this.yellow = 0;
this.blue = 0;
this.pink = 0;
this.calculateStars();
}
Die.prototype.up = function( stars )
{
if ( !stars ) stars = 1;
this.stars += stars;
this.calculateStars();
}
Die.prototype.calculateStars = function()
{
var stars = this.stars;
var blue = 0, red = 0, yellow = 0, pink = 0;
// Pink
stars -= pink = 0 | ( stars > 20 ? stars * .175 - 2.5 : 0 );
if ( pink > this.pink )
console.log( "PINK: " + (pink - this.pink) );
this.pink = pink;
// Blue
stars -= blue = 0 | ( stars * .15 );
if ( blue > this.blue )
console.log( "BLUE: " + (blue - this.blue) );
this.blue = blue;
// Yellow
stars -= yellow = 0 | ( stars * .33 );
if ( yellow > this.yellow )
console.log( "YELLOW: " + (yellow - this.yellow) );
this.yellow = yellow;
// Red
stars -= red = 0 | stars;
if ( red > this.red )
console.log( "RED: " + (red - this.red) );
this.red = red;
return this;
}
Comments