previous

page 14

next

It'll make the code far easier to read (and less typing) if we create a couple of new functions.

function show_card(id) {
var image=document.getElementById(id);
image.src='cards/'+g_cards[id]+'.png';
}
function hide_card(id) {
var image=document.getElementById(id);
image.src='cards/back.png';
}
function button_click(colr) {
Hide('buttons');
g_n++;
if (g_cards[1]==g_cards[4]) {
if (colr=='green') g_score++;
} else {
if (colr=='red') g_score++;
}
show_card(1);
show_card(4);
// wait two seconds
for (var i=0;i<5;i++) hide_card(i);
pick0();
show_card(0);
// wait three seconds
hide_card(0);
move();
for (var j=4; j>0; j--) g_cards[j]=g_cards[j-1];
// when move finished
Show('buttons');
}
previous
next