|
@ -2,6 +2,11 @@ |
|
|
function buildBoard(objectArr,canvasPointArr){ |
|
|
function buildBoard(objectArr,canvasPointArr){ |
|
|
// build board array
|
|
|
// build board array
|
|
|
let boardArr = buildBoardArray() |
|
|
let boardArr = buildBoardArray() |
|
|
|
|
|
//leiter Objekte(anfang , ende)
|
|
|
|
|
|
let leitern = [[7, 33],[24, 44],[31, 55],[60, 77]]; |
|
|
|
|
|
//schlange Objekte (anfang , ende)
|
|
|
|
|
|
let schlangen = [[99, 56], [86, 64],[60, 28],[18,1]]; |
|
|
|
|
|
dynamicObjects(leitern, schlangen) |
|
|
// draw board on screen using board array
|
|
|
// draw board on screen using board array
|
|
|
drawBoard(boardArr); |
|
|
drawBoard(boardArr); |
|
|
//draw canvas overlay
|
|
|
//draw canvas overlay
|
|
@ -12,8 +17,8 @@ function buildBoard(objectArr,canvasPointArr){ |
|
|
generateBoardObjects(leitern, schlangen, objectArr) |
|
|
generateBoardObjects(leitern, schlangen, objectArr) |
|
|
//draw board objects
|
|
|
//draw board objects
|
|
|
drawBoardObjects(canvasPointArr, objectArr) |
|
|
drawBoardObjects(canvasPointArr, objectArr) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function buildBoardArray(){ |
|
|
function buildBoardArray(){ |
|
|
let boardArr = []; |
|
|
let boardArr = []; |
|
|
let width = 10; |
|
|
let width = 10; |
|
@ -47,6 +52,82 @@ function buildBoardArray(){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function dynamicObjects(ladderArr, snakeArr){ |
|
|
|
|
|
|
|
|
|
|
|
//get the difficulty settings
|
|
|
|
|
|
//normal , intermediate, hard
|
|
|
|
|
|
//dicide number of snakes and ladders
|
|
|
|
|
|
//decide their positions
|
|
|
|
|
|
let snakeCount = 5 ; |
|
|
|
|
|
let ladderCount = 5; |
|
|
|
|
|
//everage number of rows moved
|
|
|
|
|
|
let snakeLength = 1.0 |
|
|
|
|
|
let ladderLength = 1.0 |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < snakeCount; i++){ |
|
|
|
|
|
//pick random number between 11 and 100
|
|
|
|
|
|
let minStart = Math.ceil(11); |
|
|
|
|
|
let maxStart = Math.floor(100); |
|
|
|
|
|
let start = Math.floor(Math.random() * (maxStart - minStart + 1) + minStart) |
|
|
|
|
|
//create an end point for this number
|
|
|
|
|
|
let minEnd = 10 |
|
|
|
|
|
let maxEnd = 30 |
|
|
|
|
|
|
|
|
|
|
|
//pick a seccond number not in the same decimal as the first number
|
|
|
|
|
|
let end = start - (Math.floor(Math.random() * (maxEnd - minEnd + 1) + minEnd))*snakeLength |
|
|
|
|
|
|
|
|
|
|
|
//check if its below 1
|
|
|
|
|
|
if(end <=0){ |
|
|
|
|
|
end = 1 |
|
|
|
|
|
} |
|
|
|
|
|
//add these as an [] to corisponding array
|
|
|
|
|
|
snakeArr[i] = [start,end] |
|
|
|
|
|
} |
|
|
|
|
|
for (let i = 0; i < ladderCount; i++){ |
|
|
|
|
|
//pick random number between 1 and 90
|
|
|
|
|
|
let minStart = Math.ceil(1); |
|
|
|
|
|
let maxStart = Math.floor(90); |
|
|
|
|
|
let start = Math.floor(Math.random() * (maxStart - minStart + 1) + minStart) |
|
|
|
|
|
//create an end point for this number
|
|
|
|
|
|
let minEnd = 10 |
|
|
|
|
|
let maxEnd = 30 |
|
|
|
|
|
|
|
|
|
|
|
//pick a seccond number not in the same decimal as the first number
|
|
|
|
|
|
let end = start + (Math.floor(Math.random() * (maxEnd - minEnd + 1) + minEnd))*ladderLength |
|
|
|
|
|
|
|
|
|
|
|
//check if its below 1
|
|
|
|
|
|
if(end >=100){ |
|
|
|
|
|
end = 99 |
|
|
|
|
|
} |
|
|
|
|
|
//add these as an [] to corisponding array
|
|
|
|
|
|
ladderArr[i] = [start,end] |
|
|
|
|
|
} |
|
|
|
|
|
console.log(snakeArr) |
|
|
|
|
|
console.log(ladderArr) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////forbid
|
|
|
|
|
|
//ladders at top
|
|
|
|
|
|
//snakes on bottom
|
|
|
|
|
|
//6 snake starts next to each other
|
|
|
|
|
|
//neither leading to same level (not in the same decimal)
|
|
|
|
|
|
//cannot have two starts in one spot
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function drawBoard(arr){ |
|
|
function drawBoard(arr){ |
|
|
//Tabele Element auswählen
|
|
|
//Tabele Element auswählen
|
|
|
let tbl = document.getElementById("board"); |
|
|
let tbl = document.getElementById("board"); |
|
@ -76,10 +157,6 @@ function boardObject(){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//leiter Objekte(anfang , ende)
|
|
|
|
|
|
let leitern = [[7, 33],[24, 44],[31, 55],[60, 77]]; |
|
|
|
|
|
//schlange Objekte (anfang , ende)
|
|
|
|
|
|
let schlangen = [[99, 56], [86, 64],[60, 28],[18,1]]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|