Hello so i am trying to program minesweeper and I already generated the random bombs but how do i specifically call the td tags that are right next to the bombs so i can change it to 1,2,3, or 4? I'm using javascript only. Here is the code for the bomb generator. Thanks in advance !
function generateBombs()
{
var targetTable = document.getElementsByTagName('table')[0],
used = [],
bomb = 0,
x,
y;
while (bomb <= 9)
{
y = Math.round(Math.random() * 7);
x = Math.round(Math.random() * 7);
if (used.indexOf(y + ':' + x) === -1)
{
targetTable.getElementsByTagName("tr")[y]
.getElementsByTagName('td')[x]
.innerHTML = '<img src="sweeperbomb.png" />';
used.push(y + ':' + x);
bomb++;
}
}
}
Aucun commentaire:
Enregistrer un commentaire