Есть скрипт:
var images=["Wall.png","Bomb.png","Flag.png","Spase.png"];
var position_bomb = [["","","","","","",""],["","","","","","",""],["","","","","","",""],["","","","","","",""],["","","","","","",""],["","","","","","",""],["","","","","","",""],["","","","","","",""]];
var bombs_nearby=[["","","","","","","",""],["","","","","","","",""],["","","","","","","",""],["","","","","","","",""],["","","","","","","",""],["","","","","","","",""],["","","","","","","",""],["","","","","","","",""]];
var b1,b2,b3,b4,b5,b6,b7,b8; /*Необязательная переменная (используется только в одном месте.*/
function randomBomb()
{
randomB=Math.floor(Math.random()*4);
if (randomB==1)
{
return 1;
}
else
{
return 3;
}
}
for (i=1;i<9;i++)
{
for (j=1;j<9;j++)
{
position_bomb[i-1][j-1]=randomBomb();
console.log(((position_bomb[i-1][j-1])== 1 ? (i+":"+j+" BOMB"): (i+":"+j+" None") ));
document.images["i"+i+j].src=images[0];
}
}
table.onclick = function(event) {
var target = event.target; // где был клик?
document.images[target.id].src=images[(position_bomb[(target.id[1]-1)][(target.id[2]-1)])];
};
alert()
console.log("-- -- -- -- -- --- -- - - - -")
for (i=0;i<8;i++)
{
b1=0;
b2=0;
b3=0;
b4=0;
b5=0;
b6=0;
b7=0;
b8=0;
for (j=0;j<8;j++)
{
b1=((position_bomb[i-1][j-1]==undefined ? 0 : position_bomb[i-1][j-1]))==3 ? 0 : 1;
b2=((position_bomb[i-1][j]==undefined ? 0 : position_bomb[i-1][j]))==3 ? 0 : 1;
b3=((position_bomb[i-1][j+1]==undefined ? 0 : position_bomb[i-1][j+1]))==3 ? 0 : 1;
b4=((position_bomb[i][j+1]==undefined ? 0 : position_bomb[i][j+1]))==3 ? 0 : 1;
b5=((position_bomb[i][j-1]==undefined ? 0 : position_bomb[i][j-1]))==3 ? 0 : 1;
b6=((position_bomb[i+1][j-1]==undefined ? 0 : position_bomb[i+1][j-1]))==3 ? 0 : 1;
b7=((position_bomb[i+1][j]==undefined ? 0 : position_bomb[i+1][j]))==3 ? 0 : 1;
b8=((position_bomb[i+1][j+1]==undefined ? 0 : position_bomb[i+1][j+1]))==3 ? 0 : 1;
bombs_nearby[i][j]=b1+b2+b3+b4+b5+b6+b7+b8;
console.log(bombs_nearby[i][j]);
}
}
(прошу обратить внимание после console.log("-- -- -- -- -- --- -- - - - -") ) И в последних строках, я делаю проверку на количество бомб вокруг клетки. Вот только при проверке ячейки с минусовым индексом - он выдает ошибку.