The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 5


} Close if true

else if (ev.offsetX || ev.offsetX == 0) { Can we use offsetX
and offset?

mx = ev.offsetX; Set mx

my = ev.offsetY; Set my

} Close else

var i; Declare variable for
indexing in the for
loop

for (i=0;i<deck.length;i++){ Loop through the
whole deck

var card = deck[i]; Extract a card
reference to simplify
the code

if (card.sx >=0) Check that card isn't
marked as having
been removed

if
((mx>card.sx)&&(mx<card.sx+card.swidth)&&(my>card.sy)&&(my<card
.sy+card.sheight)) {

And then check if the
mouse is over this
card

if ((firstpick)|| (i!=firstcard)) break; If so, check that the
player isn't clicking on
the first card again,
and if this is true,
leave the for loop

} Close if true clause

Close for loop

if (i<deck.length) { Was the for loop
exited early?

if (firstpick) { If this is a first pick...
Free download pdf