#dice.bas
dim rolls(10)
diceCount=1
faceCount=6
#startup routines
form title 0,0,0,0,"Dice",1
form btn 0,160,0,0,"Setup",1
form btn 40,147,30,12,"Exit",1
cls
while 1
penRes=fn pen(5)
if penRes=3
    gosub setup
    cls
elseif penRes=0
    gosub roll
elseif penRes=14
    stop
endif
wend

#subs
sub drawDice(x,y,w,num)
draw x+1,y+1,x+1,y+1
draw x+w-2,y+1,x+w-2,y+1
draw x+1,y+w-2,x+1,y+w-2
draw x+w-2,y+w-2,x+w-2,y+w-2
draw x+2,y,x+w-3,y
draw x,y+2,x,y+w-3
draw x+w-1,y+2,x+w-1,y+w-3
draw x+2,y+w-1,x+w-3,y+w-1
if num=1
draw circle x+(w/2),y+(w/2),w/10,7
endif
if num=2
draw circle x+(w/2/2),y+(w/2/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
endif
if num=3
draw circle x+(w/2),y+(w/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2/2),y+(w/2/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
endif
if num=4
draw circle x+(w/2/2),y+(w/2/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2/2),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2/2),w/10,7
endif
if num=5
draw circle x+(w/2/2),y+(w/2/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2/2),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2/2),w/10,7
draw circle x+(w/2),y+(w/2),w/10,7
endif
if num=6
draw circle x+(w/2/2),y+(w/2/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2/2),y+(w/2)+(w/4),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2/2),w/10,7
draw circle x+(w/2/2),y+(w/2),w/10,7
draw circle x+(w/2)+(w/4),y+(w/2),w/10,7
endif
end sub

sub setup
lab:
diceCount=val(input$("Number of dice"))
if diceCount>10 or diceCount<1
goto lab:
endif
end sub

sub roll
    cls
    for i=1 to diceCount
        rolls(i)=rnd(faceCount)+1
        dw=160/diceCount
        if dw>130
        dw=130
        endif
        gosub drawDice(((i-1)*dw),80-(dw/2),dw,rolls(i))
    next i

end sub
