# dice.kbs - graphical dice 2009-10-31 j.m.reneau
# doll dice and make a rolling noise while we do it.

clg
cls

# draw initial screen
color black
rect 1,1,graphwidth,graphheight

# Sound file from freesound.org
# contributed by Freegle - Sample 44061
wavplay "dicewood.wav"

for t = 1 to 6
    gosub roll
    pause rand * .2
next t
print "You Rolled " + total
pause 1	# let the sound finish
end

roll:
color white
for die = 1 to 2
	# set x and y to the top corner of the die
	gosub setdie
	rect x,y,100,100
next die
total = 0
for die = 1 to 2
	# set x and y to the top corner of the die
	gosub setdie
	roll = int(rand * 6) + 1
	total = total + roll
	if roll = 1 then gosub drawone
	if roll = 2 then gosub drawtwo
	if roll = 3 then gosub drawthree
	if roll = 4 then gosub drawfour
	if roll = 5 then gosub drawfive
	if roll = 6 then gosub drawsix
next die
refresh
return

setdie:
x = 40
y = 40
if die = 2 then x = 160
if die = 2 then y = 160
if die = 3 then x = 40
if die = 2 then y = 160
if die = 2 then x = 160
if die = 4 then y = 40
return


drawone:
color red
rect x + 40, y + 40, 20, 20
return

drawtwo:
color black
rect x + 10, y + 10, 20, 20
rect x + 70, y + 70, 20, 20
return

drawthree:
gosub drawtwo
gosub drawone
return

drawfour:
gosub drawtwo
color black
rect x + 10, y + 70, 20, 20
rect x + 70, y + 10, 20, 20
return

drawfive:
gosub drawfour
gosub drawone
return

drawsix:
gosub drawfour
color black
rect x + 10, y + 40, 20, 20
rect x + 70, y + 40, 20, 20
return




