This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMontaLabirinto.html
122 lines (96 loc) · 4.38 KB
/
MontaLabirinto.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Projeto Grafos labirintos 😐</title>
<script src="graphs.js"></script>
<style type="text/css">
#filecontents {
border: double;
overflow-y: scroll;
width: 200px;
height: 100px;
}
</style>
</head>
<body>
Por favor selecione arquivo para montar o labirinto:
<input type="file" id="txtfiletoread" /><br />
<div>Conteúdo do arquivo:</div>
<div id="filecontents">
</div>
<script>
var fileContents;
window.onload = function () {
if (window.File && window.FileReader && window.FileList && window.Blob) {
let fileSelected = document.getElementById('txtfiletoread');
fileSelected.addEventListener('change', function (e) {
let fileExtension = /text.*/;
let fileTobeRead = fileSelected.files[0];
if (fileTobeRead.type.match(fileExtension)) {
let fileReader = new FileReader();
fileReader.onload = function (e) {
fileContents = document.getElementById('filecontents');
fileContents.innerText = fileReader.result;
let data = fileContents.innerText;
let data2 = data.split('\n');
console.log(data2);
let row = [];
//row[0] = 10;
for(let i=1 ;i< data2.length;i++) {
row[i] = data2[i].split(" ");
}
console.log(row);
console.log("pirata: "+row[4][0]);
console.log("tesouro: "+row[8][0]);
//-----------------------inicie funções aqui--------------------------------------------------------------------------------------
//var num = data2[0];
//------------------------lista adjecencia-----------------------------------------------------
let graph2 = new Graph(data2[0]);
for(let i=1 ;i< data2.length-1;i++) {
for(let j=0 ;j < data2.length-1;j++) {
graph2.addVertex(String(i+"-"+j+":"+row[i][j]));
}
}
for(let i=1 ;i< data2.length-2;i++) {
for(let j=0 ;j < data2.length-1;j++) {
history(graph2,row,i,j);
}
}
function history(graph,row,i,j){
if(typeof row[i][j] !== 'undefined'){
if(row[i+1][j]==='1' || row[i+1][j]==='P' || row[i+1][j]==='X') {
graph.addEdge(String(i+"-"+j+":"+row[i][j]),String((i+1)+"-"+j+":"+row[i+1][j]));
}
if(row[i][j+1]==='1' || row[i][j+1]==='P' || row[i][j+1]==='X') {
graph.addEdge(String(i+"-"+j+":"+row[i][j]),String(i+"-"+(j+1)+":"+row[i][j+1]));
}
if(i>2){
if(row[i-1][j]==='1' || row[i-1][j]==='P' || row[i-1][j]==='X') {
graph.addEdge(String(i+"-"+j+":"+row[i][j]),String((i-1)+"-"+j+":"+row[i-1][j]));
}
if(row[i][j-1]==='1' || row[i][j-1]==='P' || row[i][j-1]==='X') {
graph.addEdge(String(i+"-"+j+":"+row[i][j]),String(i+"-"+(j-1)+":"+row[i][j-1]));
}
}
}
}
//var shortestPathA = graph2.bfs(String(8+"-"+8+":"+row[8][8]));
//console.log(shortestPathA);
}
fileReader.readAsText(fileTobeRead);
}
else {
alert("Por favor selecione arquivo texto");
}
}, false);
}
else {
alert("Arquivo(s) não suportado(s)");
}
}
</script>
<div id ="content"></div>
</body>
</html>