Dijlstra fertig implementiert + Zeichnung des Weges

master
Schoko 4 years ago
parent 5ace7839a0
commit 6d9168be89
  1. 47
      board.js
  2. 7
      index.html
  3. 18
      style.css

@ -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;

@ -2,12 +2,13 @@
<html>
<head>
<title>Perlin Noise</title>
<link rel="stylesheet" href="style.css">
<script src="dijkstra.js"></script>
<script src="board.js"></script>
</head>
<body>
<h1> Perlin Noise</h1>
<canvas id="can" width="640" height="640" style="border:1px solid #000000;"></canvas>
<button id="new_btn"> Neu </button>
<canvas id="can" width="640" height="640"></canvas>
<canvas id="can2" width="640" height="640"></canvas>
<canvas id="can3" width="640" height="640"></canvas>
</body>
</html>

@ -0,0 +1,18 @@
#parent{
position: relative;
}
#can {
position: absolute;
z-index: 1;
}
#can2 {
position: absolute;
z-index: 2;
}
#can3 {
position: absolute;
z-index: 4;
}
Loading…
Cancel
Save