//dice

int x, y, e, i, roll;

dice4()
{
frame(1,20,80,40,100,0);
text(25, 85,"d4");
}

dice6()
{
frame(1,50,80,70,100,0);
text(55, 85,"d6");
}
dice8()
{
frame(1,80,80,100,100,0);
text(85, 85,"d8");
}
dice10()
{
frame(1,20,110,40,130,0);
text(23, 115,"d10");
}

dice12()
{
frame(1,50,110,70,130,0);
text(53, 115,"d12");
}

dice20()
{
frame(1,80,110,100,130,0);
text(83, 115,"d20");}
dice100()
{
frame(1,110,80,135,100,0);
text(113, 85,"d100");
}
diceAbout()
{
frame(1,110,110,135,130,0);
text(115, 115,"Info");
}

rolldice(int sides)
{
roll=random(sides)+1;
textattr(6,1,0);
rect (0, 55,40,200,60,0);
if (roll<10) text (72,40,  roll);
if (roll>9 && roll<100) text (67,40, roll);
if (roll>=100) text (62,40, roll);
textattr(0,1,0);
}

btnpress(int tx, int bx,int ty, int by)
{
beep(7);
rect(1,tx,ty,bx,by,0);
for(i=1;i<100;i++);
rect(0,tx,ty,bx,by,0);
}

main()
{
graph_on();
title("Dice");
dice4();
dice6();
dice8();
dice10();
dice12();
dice20();
dice100();
diceAbout();
do
{
e=event(1);
x=penx();
y=peny();
if(e==2)
{
if (x>20 && x<40 && y > 80 && y<100)
{
btnpress(20, 40, 80, 100);
dice4();
rolldice(4);
}
if (x>50 && x<70 && y > 80 && y<100) 
{
btnpress(50, 70, 80, 100);
dice6();
rolldice(6);
}
if (x>80 && x<100 && y > 80 && y<100) 
{
btnpress(80,100, 80, 100);
dice8();
rolldice(8);
}
if (x>20 && x<40 && y > 110 && y<130) 
{
btnpress(20,40, 110, 130);
dice10();
rolldice(10);
}
if (x>50 && x<70 && y > 110 && y<130) 
{
btnpress(50,70, 110, 130);
dice12();
rolldice(12);
}
if (x>80 && x<100 && y > 110 && y<130) 
{
btnpress(80,100, 110, 130);
dice20();
rolldice(20);
}
if (x>110 && x<135 && y > 80 && y<100) 
{
btnpress(110,135, 80, 100);
dice100();
rolldice(100);
}
if (x>110 && x<135 && y > 110 && y<130) 
{
btnpress(110,135, 110, 130);
diceAbout();
alert("brought to you (free) by the warezird");
}
}
}
while (1);
}