forked from edusporto/maze-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrograma.java
78 lines (72 loc) · 2.21 KB
/
Programa.java
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
import java.io.*;
import labirinto.*;
import fila.*;
import pilha.*;
import coordenada.*;
public class Programa
{
public static void main (String[] args)
{
boolean parar = false;
boolean houveErro;
try
{
while (!parar)
{
houveErro = false;
BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in));
Labirinto lab;
System.out.println("============================================");
System.out.println("Resolvedor de Labirinto");
System.out.println("============================================");
System.out.println();
System.out.println("Escreva o caminho para o arquivo de um labirinto: ");
System.out.println();
String caminhoParaOArquivo = teclado.readLine();
System.out.println ();
try
{
lab = new Labirinto (caminhoParaOArquivo);
Labirinto labRes = (Labirinto)lab.labirintoResolvido().clone();
if (labRes.getHaSolucao()==0)
{
houveErro = true;
System.out.println ("Desculpe, mas nao ha solucao para este labirinto.");
}
else
{
System.out.println (labRes);
System.out.println ();
System.out.println ("Caminho percorrido pelo labirinto: ");
System.out.println (labRes.getInverso());
System.out.println ();
}
if (!houveErro)
{
System.out.println ("Deseja salvar a solucao do labirinto em um arquivo? (S/N)");
char resp = Character.toUpperCase(teclado.readLine().charAt(0));
System.out.println ();
if (resp == 'S')
{
System.out.println ("Digite o caminho para o arquivo para salvar: ");
String caminhoParaOArquivoParaSalvar = teclado.readLine();
try
{
labRes.escreverLabirintoResolvidoNoArquivo (caminhoParaOArquivoParaSalvar);
System.out.println ("Labirinto salvo com sucesso!");
}
catch (Exception e1) { System.out.println(e1); }
}
}
}
catch (Exception e2) { System.out.println(e2); }
System.out.println ();
System.out.println ("Deseja executar o programa novamente com outro labirinto? (S/N)");
char resp = Character.toUpperCase(teclado.readLine().charAt(0));
if (resp == 'N')
parar=true;
}
}
catch (Exception erro) {} // nao ocorrera
}
}