-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
119 lines (90 loc) · 3.54 KB
/
Main.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
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
import java.io.File;
import java.io.IOException;
import java.io.File;
public class Main {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Brak argumentów - koniec działania programu");
return;
}
String fileName = args[0];
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
if (!fileType.equals("txt") && !fileType.equals("bin")) {
System.out.println("Nieobsługiwany typ pliku - koniec działania programu");
return;
}
File file = new File(fileName);
if (!file.exists()) {
System.out.println("Plik nie istnieje - koniec działania programu");
return;
}
int Columns = 0;
int Rows = 0;
int EnterX = 0;
int EnterY = 0;
int ExitX = 0;
int ExitY = 0;
File file2 = new File("Labirynt.png");
file2.delete();
if (fileType.equals("txt")) {
try {
Columns = txtFileReader.Columns(file);
Rows = txtFileReader.Rows(file);
int[][] Lab = txtFileReader.TxtToInt(file, Columns, Rows);
int[] BeginEnd = txtFileReader.BeginningEnd(file, Columns, Rows);
EnterX = BeginEnd[0];
EnterY = BeginEnd[1];
ExitX = BeginEnd[2];
ExitY = BeginEnd[3];
System.out.println("Columns: " + Columns + "\nRows: " + Rows + "\nEnterX: " + EnterX + "\nEnterY: " + EnterY + "\nExitX: " + ExitX + "\nExitY: " + ExitY);
System.out.println("Labirynt:");
/* for (int i = 0; i < Rows; i++) {
for (int j = 0; j < Columns; j++) {
System.out.print(Lab[j][i]);
}
System.out.println();
}*/
new GUI(Lab, Columns, Rows, EnterX, EnterY, ExitX, ExitY, "txt");
} catch (Exception e) {
System.err.println(e);
System.out.println("Błąd odczytu pliku - koniec działania programu");
return;
}
} else if (fileType.equals("bin")) {
String inputFile = args[0];
int[][] Lab = null;
short[] Data = null;
try {
Data = binFileReader.Data(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
Columns = Data[0];
Rows = Data[1];
EnterX = Data[2]-1;
EnterY = Data[3]-1;
ExitX = Data[4]-1;
ExitY = Data[5]-1;
System.out.println("Columns: " + Columns);
System.out.println("Rows: " + Rows);
System.out.println("EnterX: " + EnterX);
System.out.println("EnterY: " + EnterY);
System.out.println("ExitX: " + ExitX);
System.out.println("ExitY: " + ExitY);
try {
Lab = binFileReader.BinToInt(inputFile,Columns,Rows,EnterX,EnterY,ExitX,ExitY);
} catch (IOException e) {
throw new RuntimeException(e);
}
/*
for (int i = 0; i < Rows; i++) {
for (int j = 0; j < Columns; j++) {
System.out.print(+Lab[j][i]);
}
System.out.println();
}
*/
new GUI(Lab, Columns, Rows, EnterX, EnterY, ExitX, ExitY, "bin");
}
}
}