xxxxxxxxxx
71
class Dice{
constructor(x,y, size)
{
this.x=x;
this.y=y;
this.size=size;
this.score=0;
}
roll(){
this.score=floor(random(1,7));
}
show(){
noFill();
rect(this.x, this.y, this.size, this.size);
switch(this.score)
{
case 1:
fill(0);
circle(this.x+(this.size/2), this.y+(this.size/2),this.size/8);
break;
case 2:
fill(0);
circle(this.x+(this.size/4), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size-(this.size/4)),this.size/8);
break;
case 3:
fill(0);
circle(this.x+(this.size/4), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size-(this.size/4)),this.size/8);
circle(this.x+(this.size/2), this.y+(this.size/2),this.size/8);
break;
case 4:
fill(0);
circle(this.x+(this.size/4), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size-(this.size/4)),this.size/8);
circle(this.x+(this.size/4), this.y+this.size-(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size/4),this.size/8);
break;
case 5:
fill(0);
circle(this.x+(this.size/4), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size-(this.size/4)),this.size/8);
circle(this.x+(this.size/4), this.y+this.size-(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size/2), this.y+(this.size/2),this.size/8);
break;
case 6:
fill(0);
circle(this.x+(this.size/4), this.y+(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size-(this.size/4)),this.size/8);
circle(this.x+(this.size/4), this.y+this.size-(this.size/4),this.size/8);
circle(this.x+(this.size-(this.size/4)), this.y+(this.size/4),this.size/8);
circle(this.x+this.size-(this.size/4), this.y+(this.size/2),this.size/8);
circle(this.x+(this.size/4), this.y+(this.size/2),this.size/8);
break;
}
}
}