-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventListener.js
93 lines (71 loc) · 2.1 KB
/
eventListener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
canvas.addEventListener("mousedown",function(e){
mouseDown=true;
if(mouseDown==true){
mX=e.x;
mY=e.y;
for(var i=0;i<arr.length;i++){
if(mX >= arr[i].X && mX <= arr[i].X+size && mY>=arr[i].Y && mY<=arr[i].Y+size){
if(block_point==true){
arr[i].roadBlock(arr[i].X,arr[i].Y,i);
if(blockedPath.includes(i)){
//do nothing
}
else{
blockedPath.push(i);
console.log(blockedPath);
}
}
if(start_point==true){
arr[i].currentWeight=0;
arr[i].startPath(arr[i].X,arr[i].Y,i);
startCell.x=arr[i].X;
startCell.y=arr[i].Y;
startCell.index=i;
startpoint=i;
arr[i].previous=i;
document.getElementById('startAddress').innerHTML=startCell.x+","+startCell.y;
console.log("startCell="+startCell.x+","+startCell.y+","+startCell.index);
}
if(end_point==true){
arr[i].endPath(arr[i].X,arr[i].Y,i);
endCell.x=arr[i].X;
endCell.y=arr[i].Y;
endCell.index=i;
pathIndex=i;
document.getElementById('endAddress').innerHTML=endCell.x+","+endCell.y;
console.log("endCell="+endCell.x+","+endCell.y+","+endCell.index);
}
//currentCell=arr[i];
//endCell=arr[i+50];
// blockedPath.push(arr[i]);
// blockedPath.push(currentCell);
//console.log("Colored: "+arr[i].X+","+arr[i].Y);
//break;
}
}
}
});
canvas.addEventListener("mouseup",function(e){
mouseDown=false;
});
canvas.addEventListener("mousemove",function(e){
if(mouseDown==true){
mX=e.x;
mY=e.y;
for(var i=0;i<arr.length;i++){
if(mX >= arr[i].X && mX <= arr[i].X+size && mY>=arr[i].Y && mY<=arr[i].Y+size){
if(block_point==true){
arr[i].roadBlock(arr[i].X,arr[i].Y,i);
if(blockedPath.includes(i)){
//do nothing
}
else{
blockedPath.push(i);
console.log(blockedPath);
}
}
break;
}
}
}
});