|
|
@ -1,6 +1,20 @@ |
|
|
|
//ein Array erstellen, aus dem die Spilebrett gezeichnet werden kann
|
|
|
|
function buildBoard(objectArr,canvasPointArr){ |
|
|
|
// build board array
|
|
|
|
let boardArr = buildBoardArray() |
|
|
|
// draw board on screen using board array
|
|
|
|
drawBoard(boardArr); |
|
|
|
//draw canvas overlay
|
|
|
|
drawCanavas() |
|
|
|
// cast points to center of board cells
|
|
|
|
canvasPointGen(canvasPointArr); |
|
|
|
// add snakes and ladders objects to object array
|
|
|
|
generateBoardObjects(leitern, schlangen, objectArr) |
|
|
|
//draw board objects
|
|
|
|
drawBoardObjects(canvasPointArr, objectArr) |
|
|
|
|
|
|
|
} |
|
|
|
function buildBoardArray(){ |
|
|
|
let boardArr = []; |
|
|
|
let width = 10; |
|
|
|
let height = 10; |
|
|
@ -29,20 +43,8 @@ function buildBoard(objectArr,canvasPointArr){ |
|
|
|
} |
|
|
|
boardArr.push(row) |
|
|
|
} |
|
|
|
// draw board on screen using board array
|
|
|
|
drawBoard(boardArr); |
|
|
|
//draw canvas overlay
|
|
|
|
drawCanavas() |
|
|
|
// cast points to center of board cells
|
|
|
|
canvasPointGen(canvasPointArr); |
|
|
|
// add snakes and ladders objects to object array
|
|
|
|
generateBoardObjects(leitern, schlangen, objectArr) |
|
|
|
//draw board objects
|
|
|
|
drawBoardObjects(canvasPointArr, objectArr) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return boardArr; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function drawBoard(arr){ |
|
|
@ -256,30 +258,7 @@ function drawBoardObjects(canvasPointArr, objectArray){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function checkPosition(player, objectArr){ |
|
|
|
|
|
|
|
//above 100
|
|
|
|
if(player.newPosition > 100){ |
|
|
|
player.newPosition = 100; |
|
|
|
} |
|
|
|
//win condition
|
|
|
|
if(player.newPosition == 100){ |
|
|
|
player.won = true; |
|
|
|
changeElement("continue", "block") |
|
|
|
changeElement("replay", "block") |
|
|
|
changeElement("würfelBereich", "none") |
|
|
|
} |
|
|
|
|
|
|
|
//snake condition
|
|
|
|
//ladder condition
|
|
|
|
for(let i = 0; i < (objectArr.length) ; i++){ |
|
|
|
if(player.newPosition == objectArr[i].start){ |
|
|
|
player.newPosition = objectArr[i].end; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function continueGame (){ |
|
|
|
|
|
|
|