|
|
@ -1,12 +1,12 @@ |
|
|
|
//ein Array erstellen, aus dem die Spilebrett gezeichnet werden kann
|
|
|
|
function buildBoard(){ |
|
|
|
function buildBoard(objectArr,canvasPointArr){ |
|
|
|
|
|
|
|
let boardArr = []; |
|
|
|
let width = 10; |
|
|
|
let height = 10; |
|
|
|
let count = 100 |
|
|
|
let direction = 0 //0 = gerade reihe (links nach Rechts) ; 1 = ungerade reihe (rechts nach Links)
|
|
|
|
|
|
|
|
// construct board array
|
|
|
|
for(var y = 0; y < height ; y++){ |
|
|
|
let row = []; |
|
|
|
if(direction == 0){ |
|
|
@ -29,14 +29,20 @@ function buildBoard(){ |
|
|
|
} |
|
|
|
boardArr.push(row) |
|
|
|
} |
|
|
|
console.log(boardArr) |
|
|
|
return boardArr; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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 drawBoard(arr){ |
|
|
@ -57,11 +63,6 @@ function drawBoard(arr){ |
|
|
|
cell.innerHTML = (arr[y][x]); |
|
|
|
} |
|
|
|
} |
|
|
|
// add drawing of snakes and ladders
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//spielbrett objekt Struktur
|
|
|
@ -100,6 +101,9 @@ function generateBoardObjects (leitern, schlangen, objectArray){ |
|
|
|
objectArray.push(schlange); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//make a canvas the same size as the playbaord
|
|
|
|
function drawCanavas(){ |
|
|
|
var ctx = document.getElementById("canvas"); |
|
|
@ -215,7 +219,7 @@ function drawLine(type, startPosX, startPosY, endPosX, endPosY){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function createBoardObjects(canvasPointArr, objectArray){ |
|
|
|
function drawBoardObjects(canvasPointArr, objectArray){ |
|
|
|
//loop through all object in the object array
|
|
|
|
for(let i = 0; i < objectArray.length; i++){ |
|
|
|
|