this.intRand = function(maxVal)
{
return Math.floor((maxVal‑1) * Math.random() + 0.5) — 1;
}
this.fillMines = function()
{
var res = new Array(this.rowCount * this.colCount);
var mines = this.minesCount;
while (mines > 0)
{
var n = this.intRand(this.rowCount * this.colCount‑1);
if (res[n] != 1)
{
res[n] = 1;
mines--;
}
}
return res;
}
this.hasMine = function(i, j)
{
if ((i < 0) || (j < 0) || (i >= this.rowCount) || (j >= this.colCount))
return 0;
if (this.mines[i * this.rowCount + j] == 1)
return 1;
return 0;
}
this.checkCell = function(i, j)
{
if (this.hasMine(i, j))