//先按顺序排列 for (var i = 0; i < mineNumber; i++) { var row = parseInt(i / this.colCount); var col = i % this.colCount; //使用数字 9 表示该区域有雷 tmpMineMap[row][col] = 9; }
//定义交换的次数,次数越多越混乱随机 var swapTime = 100; for (var i = 0; i < swapTime; i++) { //随机位置1 var row1 = this.rangeRandom(0, this.rowCount - 1); var col1 = this.rangeRandom(0, this.colCount - 1); //随机位置2 var row2 = this.rangeRandom(0, this.rowCount - 1); var col2 = this.rangeRandom(0, this.colCount - 1); //交换两个位置 var temp = tmpMineMap[row1][col1]; tmpMineMap[row1][col1] = tmpMineMap[row2][col2]; tmpMineMap[row2][col2] = temp; }
朋友会在“发现-看一看”看到你“在看”的内容