The Essential Guide to HTML5

(Greg DeLong) #1

ROCK, PAPER, SCISSORS


Code Explanation


<canvas id="canvas" width="600" height=
"400">


Starting canvas tag

Your browser doesn't support the HTML5
element canvas.


Message for noncompliant browsers

Closing tag


Line break


Starting tag for form, giving form a name

Score: <input name="score" value="0"
size="3"/>


Label and then input field, with initial value
and size

Closing tag for form
Closing tag for body
Closing tag for html document
The audio enhanced version required three more global variables along with additions in the init, choose
and flyin functions. The new global variables are

var music = [
[3,1,0],
[1,3,2],
[0,2,3]];
var musicelements;
var musicch;

Here is the clause in the choose function with the new line highlighted.

if ((mx>ch.sx)&&(mx<ch.sx+ch.bwidth)&&(my>ch.sy)&&(my<ch.sy+ch.bheight)) {
drawall();
size = 15;
tid = setInterval(flyin,100);
result = beats[compch][i];
musicch = music[compch][i];
newscore = Number(document.f.score.value);
newscore +=points[compch][i];
break;
}

Similarly, heres the complete flyin function with the new line in bold:
Free download pdf