Andrew2010 Posted November 15, 2010 Share Posted November 15, 2010 Hi everybody, I've added a memory game to my site. The game has 6 rows, and 5 columns (30 cards), and I was wondering if someone could fix the script so it has 5 rows and 6 colums. I'm not sure which script controls it, so here's them both: document.write('<div align="center"><table cellpadding="0" cellspacing="0" border="0">');for (var a = 0; a <= 5; a++) {document.write('<tr>');for (var b = 0; b <= 4; b++) {document.write('<td align="center" class="blk" id="t'+((5*a)+b)+'"></td>');}document.write('<\/tr>');}document.write('<\/table><form name="mem"><input type="button" id="cnt" value="0:00" onclick="window.start()" \/><\/form><\/div>'); var back = 'images/back.gif'; var tile = ['images/card0.gif','images/card1.gif','images/card2.gif','images/card3.gif','images/card4.gif','images/card5.gif', 'images/card6.gif','images/card7.gif','images/card8gif','images/card9.gif','images/card10.gif','images/card11.gif', 'images/card12.gif','images/card13.gif','images/card14.gif']; function randOrd(a, b){return (Math.round(Math.random())-0.5);} var im = []; for (var i = 0; i < 15; i++) {im[i] = new Image(); im[i].src = tile[i]; tile[i] = '<img src="'+tile[i]+'" width="60" height="100" alt="" \/>'; tile[i+15] = tile[i];} function displayBack(i) {document.getElementById('t'+i).innerHTML = '<div onclick="disp('+i+');return false;"><img src="'+back+'" width="60" height="100" alt="back" \/><\/div>';} var ch1, ch2, tmr, tno, tid, cid, cnt; window.onload=start; function start() {for (var i = 0; i <= 29 ;i++) displayBack(i);clearInterval(tid);tmr = tno = cnt = 0;tile.sort( randOrd );cntr(); tid = setInterval('cntr()', 1000);} function cntr() {var min = Math.floor(tmr/60);var sec = tmr%60;document.getElementById('cnt').value = min+':'+ (sec<10 ? '0' : '') + sec;tmr++;} function disp(sel) {if (tno>1) {clearTimeout(cid); conceal();}document.getElementById('t'+sel).innerHTML = tile[sel];if (tno==0) ch1 = sel;else {ch2 = sel; cid = setTimeout('conceal()', 900);}tno++;} function conceal() {tno = 0; if (tile[ch1] != tile[ch2]) {displayBack(ch1);displayBack(ch2);} else cnt++; if (cnt >= 15) clearInterval(tid);} Thanks!! Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 15, 2010 Share Posted November 15, 2010 Hmm, I'm not going to take the time to try and interpret that code - especially since you didn't bother adding line breaks or any other formatted to help interpret it. But, you can try changing (var a = 0; a <= 5; a++) To (var a = 0; a < 5; a++) And (var b = 0; b <= 4; b++) To (var b = 0; b < 6; b++) Quote Link to comment Share on other sites More sharing options...
Andrew2010 Posted November 16, 2010 Author Share Posted November 16, 2010 I tried what you said, it adds 6 only on the first row. Here's the code with linebreaks: document.write('<div align="center"><table cellpadding="0" cellspacing="0" border="0">');for (var a = 0; a <= 5; a++) {document.write('<tr>');for (var b = 0; b <= 4; b++) {document.write('<td align="center" class="blk" id="t'+((5*a)+b)+'"></td>');} document.write('<\/tr>');}document.write('<\/table><form name="mem"><input type="button" id="cnt" value="0:00" onclick="window.start()" \/><\/form><\/div>'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.