|
|
|
@ -111,7 +111,7 @@ function createBoard(height, width, array){ |
|
|
|
|
|
|
|
|
|
var color = array[i][j].color; |
|
|
|
|
context.fillStyle = tilesColor[color]; |
|
|
|
|
context.fillRect(i*tile_height+1, j*tile_width+1, tile_width, tile_height); |
|
|
|
|
context.fillRect(i*tile_height, j*tile_width, tile_width, tile_height); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -288,13 +288,48 @@ function moveShip(canvas, e){ |
|
|
|
|
var y = Math.floor(e.clientY - rect.top); |
|
|
|
|
var ship = new Ship(x,y,5); |
|
|
|
|
ship.draw(canvas.getContext("2d")); |
|
|
|
|
//console.log("x: "+x+" y: "+y);
|
|
|
|
|
console.log("x: "+x+" y: "+y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function paintPath(path){ |
|
|
|
|
console.log("hier passiert was");
|
|
|
|
|
//var board = document.getElementById("can");
|
|
|
|
|
//context = board.getContext("2d");
|
|
|
|
|
var can2 = document.getElementById("can2"); |
|
|
|
|
var context = can2.getContext("2d"); |
|
|
|
|
var can3 = document.getElementById("can3"); |
|
|
|
|
var context3 = can2.getContext("2d"); |
|
|
|
|
//context.beginPath();
|
|
|
|
|
for(var i = 0; i < path.length; i++){ |
|
|
|
|
var split = path[i].split("$"); |
|
|
|
|
// console.log(split);
|
|
|
|
|
var row = Number(split[0]); |
|
|
|
|
var col = Number(split[1]); |
|
|
|
|
|
|
|
|
|
context.fillStyle = "#82b74b"; |
|
|
|
|
context.fillRect(row*tile_height, col*tile_width, tile_width, tile_height); |
|
|
|
|
//var ship = new Ship(row,col,5);
|
|
|
|
|
//context3.clearRect(0, 0, 640, 640);
|
|
|
|
|
//ship.draw(can3.getContext("2d"));
|
|
|
|
|
//context.fillStyle = "red";
|
|
|
|
|
//context.fillRect(0, 0, 1000, 1000);
|
|
|
|
|
//context.clearRect(0, 0, board.width, board.height);
|
|
|
|
|
//context.clearRect(row*tile_height, col*tile_width, tile_width, tile_height);
|
|
|
|
|
//context.beginPath();
|
|
|
|
|
//context.clearRect(0, 0, 1000, 1000);
|
|
|
|
|
//console.log("ende");
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.onload = (function(){ |
|
|
|
|
var can = document.getElementById("can"); |
|
|
|
|
rect = can.getBoundingClientRect(); |
|
|
|
|
can.addEventListener('mousedown', function(e){ |
|
|
|
|
var can2 = document.getElementById("can2"); |
|
|
|
|
var can3 = document.getElementById("can3"); |
|
|
|
|
|
|
|
|
|
rect = can3.getBoundingClientRect(); |
|
|
|
|
can3.addEventListener('click', function(e){ |
|
|
|
|
var x = Math.floor((e.clientX - rect.left)/tile_width); |
|
|
|
|
var y = Math.floor((e.clientY - rect.top )/tile_height); |
|
|
|
|
if(clickCounter === 2){ |
|
|
|
@ -303,7 +338,9 @@ window.onload = (function(){ |
|
|
|
|
endy = y; |
|
|
|
|
console.log(startx+" "+starty+" : "+endx+" "+endy);
|
|
|
|
|
currentBoardArray = createBoardArray(current_noise, height, width); |
|
|
|
|
dijkstra(currentBoardArray, startx, starty,endx,endy); |
|
|
|
|
var path = dijkstra(currentBoardArray, startx, starty,endx,endy); |
|
|
|
|
paintPath(path);
|
|
|
|
|
//moveShip(can, e);
|
|
|
|
|
} else { |
|
|
|
|
clickCounter++; |
|
|
|
|
startx = x; |
|
|
|
|