The Essential Guide to HTML5

(Greg DeLong) #1

ROCK, PAPER, SCISSORS


Code Explanation


ctx.drawImage(compimg, 70,
100,size,size);


Draw the computer-move image on the screen
at the indicated place and with dimensions
indicated

size +=5; Change the value of the dimensions by
incrementing size


if (size>50) { Use the size variable to see if the process
has gone on long enough


clearInterval(tid); Stop the timing event


ctx.fillText(result,


200,100,250);


Display the message

document.f.score.value
= String(newscore);


Display the new score. See the section below
the table for the addition for audio

} Close of if true clause


} Close of function


var rockb = new Throw(rockbx,rockby,8,50,
50,"rgb(250,0,0)","rock.jpg");


Create the rock object

var paperb = new
Throw(paperbx,paperby,8,50,
50,"rgb(0,200,200)","paper.gif");


Create the paper object

var scib = new Throw(scissorsbx,scissorsby,
8,50,50,"rgb(0,0,200)","scissors.jpg");


Create the scissors object

everything.push(rockb); Add the rock object to the everything array


everything.push(paperb); Add the paper object to the everything array


everything.push(scib); Add the scissors object to the everything
array


function init(){ Header for function called on load of the
document


document.f.score.value = "0"; Set score to zero. I also could use

Free download pdf