у меня такой вопрос
я недавно начал изучать javascript /html/css
при нажатии клавиши
в консоли выводит undefined
function getRandomInt(min, max)
{ return Math.floor(Math.random() * (max - min + 1)) + min; }
function Button_Mine(MinesCount,Mine)
{
this.MinesCount = MinesCount;
this.Mine = Mine;
this.link = 0;
console.log(this.Mine +" "+ this.MinesCount+" "+this.link);
}
Button_Mine.prototype.click = function()
{
if(this.Mine == 1)
{
alert("вы проиграли");
}
console.log(this.Mine);
console.log(this.MinesCount+" "+this.Mine);
}
function map(cols,lines,CountOfMines)
{
this.CountOfMines = CountOfMines;
this.Cols = cols;
this.Lines = lines;
this.Element = Array(this.Cols);
for (var i =0;i<this.Cols;i++)
{this.Element[i] =Array(this.Lines);
for (var j = 0;j<this.Lines;j++)
{
this.Element[i][j] =new Button_Mine(0,0);
}
}
console.log(this.Cols);
}
map.prototype.Create = function()
{
for (var i = 0;i<this.Cols;i++){for (var j =0;j<this.Lines;j++){
document.write("<button id=\"b"+i+j+"\">"+"</button>");
this.Element[i][j].link = document.getElementById("b"+i+j);
this.Element[i][j].link.addEventListener("click",this.Element[i][j].click,"false");
}}}
map.prototype.SetMines = function()
{
var i = 0;
var int1 , int2;
console.log("CountOfMines = " + this.CountOfMines);
while(i <=this.CountOfMines)
{
int1 = getRandomInt(0,(this.Cols)-1);
int2 = getRandomInt(0,(this.Lines)-1);
if(this.Element[int1][int2].Mine==1)
{
int1 = getRandomInt(0,(this.Cols)-1);
int2 = getRandomInt(0,(this.Lines)-1);
}
console.log(this.Cols+" "+int1+" "+int2);
console.log(this.Lines);
this.Element[int1][int2].Mine = 1;
this.Element[int1][int2].link.style.backgroundColor="red";
i++;
}
}
map.prototype.CheckCountOfMines = function()
{
for (var i = 0;i<this.Cols;i++)
{
for (var j = 0;j<this.Lines;j++)
{
if((i>0) && (j>0) && this.Element[i-1][j-1].Mine == true){this.Element[i][j].CountOfMines++;}
if((j>0) && this.Element[ i ][j-1].Mine == true){this.Element[i][j].CountOfMines++;}
if((i<this.Cols-1)&& (j>0) && this.Element[i+1][j-1].Mine == true){this.Element[i][j].CountOfMines++;}
if((i>0) && this.Element[i-1][ j ].Mine == true){this.Element[i][j].CountOfMines++;}
if((i<this.Cols-1) && this.Element[i+1][ j ].Mine == true){this.Element[i][j].CountOfMines++;}
if((i>0) && (j<this.Lines-1) && this.Element[i-1][j+1].Mine == true){this.Element[i][j].CountOfMines++;}
if((j<this.Lines-1) && this.Element[ i ][j+1].Mine == true){this.Element[i][j].CountOfMines++;}
if((i<this.Cols-1)&& (j<this.Lines-1) && this.Element[i+1][j+1].Mine == true){this.Element[i][j].CountOfMines++;}
}
}
console.log(this.Cols);
}
function Button_Mine(MinesCount,Mine)
{
this.MinesCount = MinesCount;
this.Mine = Mine;
this.link = 0;
}
Button_Mine.prototype.click = function()
{
if(this.Mine == 1)
{
alert("вы проиграли");
}
console.log(this.Mine);
console.log(this.MinesCount+" "+this.Mine);
}
var Map = new map(10,10,10);
Map.Create();
Map.SetMines();
Map.CheckCountOfMines();