
previous

page 13
next
the g_temp_col array
The catch is ... we haven't done anything about the g_temp_col array except to set it up as a global (well I hope you did that!)
deal() is reponsible for first setting up the game so we need to add g_temp_col=[-1,-1,-1,-1]; at the end of deal().
Notice that, unlike main, there can only be ONE card in each of the four positions - either an empty or a card.
And, as with main, we will work only with the arrays behind the scenes and rely on draw() to 'paint' the screen.
function draw() {
// temp
for (var i=0;i<4;i++) {
var el=document.getElementById(100+i);
var j=g_temp_col[i];
if (j==-1) {
el.src='cards/empty.png';
} else {
el.src='cards/'+j+'.png';
}
}
// main
for (var c=1;c<9;c++) {
var ids=g_main_cols[c];
for (var i=0;i<ids.length;i++) {
var id=ids[i]; var r=i+1;
var el=document.getElementById(id);
el.style.gridRowStart=r;
el.style.gridColumnStart=c;
el.style.zIndex=g_z; g_z++;
}
}
}
// temp
for (var i=0;i<4;i++) {
var el=document.getElementById(100+i);
var j=g_temp_col[i];
if (j==-1) {
el.src='cards/empty.png';
} else {
el.src='cards/'+j+'.png';
}
}
// main
for (var c=1;c<9;c++) {
var ids=g_main_cols[c];
for (var i=0;i<ids.length;i++) {
var id=ids[i]; var r=i+1;
var el=document.getElementById(id);
el.style.gridRowStart=r;
el.style.gridColumnStart=c;
el.style.zIndex=g_z; g_z++;
}
}
}
previous
next