The Essential Guide to HTML5

(Greg DeLong) #1

DICE GAME


break; Break out of the switch


case 4: If it is 4


draw4(); Call the draw4 function


break; Break out of the switch


case 5: If it is 5


draw4(); Call the draw4 function and then


draw1(); Call the draw1 function


break; Break out of the switch


case 6: If it is 6


draw4(); Call the draw4 function and then


draw2mid(); Call the draw2mid function


break; Break out of the switch (not strictly necessary)


} Close the switch statement


} Close the drawface function


function draw1() { Start of the definition of draw1


var dotx; Variable to be used for the horizontal position for
drawing the single dot


var doty; Variable to be used for the vertical position for
drawing the single dot


ctx.beginPath(); Start a path


dotx = dicex + .5*dicewidth; Set the center of this dot to be at the center of the
die face horizontally and


doty = dicey + .5*diceheight; ... vertically


ctx.arc(dotx,doty,dotrad,0,Math.PI*2,true); Construct a circle (which is drawn with the fill
command)

Free download pdf