Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   выводит undefined как исправить ? (https://javascript.ru/forum/dom-window/52785-vyvodit-undefined-kak-ispravit.html)

Gamer4253 06.01.2015 22:24

выводит undefined как исправить ?
 
у меня такой вопрос
я недавно начал изучать 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();

Gamer4253 06.01.2015 22:25

html
Код:

<!DOCTYPE html>
<html>
<link rel="stylesheet" href="Mines.css">

  <head>
   
    <meta charset="UTF-8">
    <title>сапер</title>
</head>
<body>
 
 <div>
<header>
</header>

 <script src="Mines2.js"></script>
 
    <script src="Button_Mine.js"></script>
    </div>
 
    </body>
</html>

css
Код:


*
{
transition : .1s;
    padding:0px;
    margin:0px;
 ;
}

body
{
    display:block;
  background-color:#ddac29;
    margin:auto;
}
div
{
    margin-top:100px;
   
    margin-bottom:auto;
 
    margin-left:auto;
    margin-right:auto;
    width:400px;
    height:400px;
    box-shadow:1px 1px 20px 10px #3d4083;
    max-width:400px;
    max-height:400px;
    border-radius:1%;
}
div.itemsforgame
{
   
width:200px;
    height:200px;
    background:#fff;
    border-radius:50%;
    margin-left:50%;
    margin-right:50%;
    margin-bottom:50%;
    box-shadow:00px 00px px 20px rgba(0,0,0,.4);
}

button
{
width:40px;
height:40px;
margin:0px;
background-color:#4c50aa;

margin:0px auto;
float:left;
    border-radius:1%;

}
.clicked
{
background-color:#ff0000;
background:url('%D0%91%D0%B5%D0%B7%D1%8B%D0%BC%D1%8F%D0%BD%D0%BD%D1%8B%D0%B9.gif') center ;
}
.mines
{
background-color:#00be00;


}
button:hover
{
    background-color:#fff;
}
button:active
{

    box-shadow:0px 0px 0px 0px rgb(128, 59, 0);


}


.score
{  text-align:center;
   
    width:400px;
    height:100px;
    margin:20px 0 0 0;
    background:#c13b00;
    border-color:white;
    box-shadow:0px 20px 0px 0px rgb(128, 59, 0);
    border-radius:5%;
}
button.score
{
text-align:center;
   
    width:100px;
    height:100px;
    margin:20px 0 0 0;
    background:#c13b00;
    border-color:white;
    box-shadow:0px 20px 0px 0px rgb(128, 59, 0);
    border-radius:50%;
    border-style:none;
   
}
button.score:active
{
-webkit-transform:translate(0,20px);
    box-shadow:0px 0px 0px 0px rgb(128, 59, 0);


}


Gamer4253 06.01.2015 23:02

я думаю это из-за того что я память неправильно определяю
где то здесь

this.Element[i][j] = new Button_Mine(0,0);


Часовой пояс GMT +3, время: 08:44.