|
@ -1,34 +1,66 @@ |
|
|
|
|
|
function buildBoard(){ |
|
|
|
|
|
|
|
|
function drawBoard(){ |
|
|
|
|
|
|
|
|
let boardArr = []; |
|
|
|
|
|
let width = 10; |
|
|
|
|
|
let height = 10; |
|
|
|
|
|
let count = 100 |
|
|
|
|
|
let direction = 0 //0 = even row (left to right) ; 1 = odd row (right to left)
|
|
|
|
|
|
|
|
|
|
|
|
for(var y = 0; y < height ; y++){ |
|
|
|
|
|
|
|
|
|
|
|
let row = []; |
|
|
|
|
|
|
|
|
|
|
|
if(direction == 0){ |
|
|
|
|
|
for(var x = 0; x < width; x++ ){ |
|
|
|
|
|
row.push(count); |
|
|
|
|
|
count--; |
|
|
|
|
|
} |
|
|
|
|
|
direction = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (direction == 1) { |
|
|
|
|
|
for(var x = 0; x < width; x++ ){ |
|
|
|
|
|
row.unshift(count); |
|
|
|
|
|
count -- |
|
|
|
|
|
} |
|
|
|
|
|
direction = 0; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
console.log("board Build error, direction corrupted") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boardArr.push(row) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(boardArr) |
|
|
|
|
|
return boardArr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function drawBoard(arr){ |
|
|
|
|
|
|
|
|
let count = 100; |
|
|
|
|
|
let tbl = document.getElementById("board"); |
|
|
let tbl = document.getElementById("board"); |
|
|
|
|
|
|
|
|
for (let y = 0; y < 10; y++){ |
|
|
|
|
|
|
|
|
for(let y = 0; y < arr.length; y++){ |
|
|
|
|
|
|
|
|
let myRow = document.createElement("tr"); |
|
|
let myRow = document.createElement("tr"); |
|
|
myRow.id = "row" + (9 -y); |
|
|
|
|
|
|
|
|
myRow.id = "row" + y; |
|
|
tbl.appendChild(myRow); |
|
|
tbl.appendChild(myRow); |
|
|
let row = document.getElementById("row" + (9 -y)); |
|
|
|
|
|
|
|
|
let row = document.getElementById("row" + y ); |
|
|
|
|
|
|
|
|
|
|
|
for(let x = 0; x < arr[y].length; x++){ |
|
|
|
|
|
|
|
|
if(y == 0 || (y % 2 == 0) ){ |
|
|
|
|
|
for(let x = 0; x < 10; x++){ |
|
|
|
|
|
count--; |
|
|
|
|
|
let cell = document.createElement("td"); |
|
|
let cell = document.createElement("td"); |
|
|
cell.id = "cell" + x |
|
|
|
|
|
|
|
|
cell.id = "cell" + arr[y][x]; |
|
|
row.appendChild(cell); |
|
|
row.appendChild(cell); |
|
|
cell.innerHTML = (count) |
|
|
|
|
|
|
|
|
cell.innerHTML = (arr[y][x]); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
for(let x = 0, z = 9; x < 10; x++, z--){ |
|
|
|
|
|
count--; |
|
|
|
|
|
let cell = document.createElement("td"); |
|
|
|
|
|
cell.id = "cell" + x |
|
|
|
|
|
row.appendChild(cell); |
|
|
|
|
|
cell.innerHTML = ((count - z) + x) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -44,3 +76,6 @@ function drawBoard(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|