The Essential Guide to HTML5

(Greg DeLong) #1

THE MEMORY (AKA CONCENTRATION) GAME


for (i=1;i<this.n;i++) { For loop for the
successive points


ctx.lineTo(this.sx+radMath.cos((i-
.5)
this.angle),this.sy+radMath.sin((i-.5)this.angle));


Set up drawing of line
segments

} Close for loop


ctx.fill(); Fill in the path


} Close function


function drawback() { Function header


ctx.fillStyle = backcolor; Set card back color


ctx.fillRect(this.sx,this.sy,this.swidth,this.sheight);
Draw rectangle


} Close function


function choose(ev) { Function header for
choose (click on a
card)


var mx; Variable to hold
mouse x


var my; Variable to hold
mouse y


var pick1; Variable to hold
reference to created
Polygon object


var pick2; Variable to hold
reference to created
Polygon object


if ( ev.layerX || ev.layerX == 0) { Can we use layerX
and layerY?


mx= ev.layerX; Set mx


my = ev.layerY; Set my

Free download pdf