-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileManager.java
More file actions
95 lines (79 loc) · 3.46 KB
/
Copy pathTileManager.java
File metadata and controls
95 lines (79 loc) · 3.46 KB
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
import java.io.*;
import java.awt.Point;
import java.util.*;
public class TileManager {
private Map<Point, String> tileTypes = new HashMap<>();
public TileManager() {
loadTileTypes();
}
public void setTileType(double col, double row, String type) {
tileTypes.put(new Point((int)Math.round(col), (int)Math.round(row)), type);
}
public String getTileType(double col, double row) {
return tileTypes.getOrDefault(new Point((int)Math.round(col), (int)Math.round(row)), "");
}
public boolean isCastleOrDonjon(double col, double row) {
String t = getTileType(col, row);
return t.equalsIgnoreCase("chateau") || t.equalsIgnoreCase("donjon");
}
public boolean isImpraticale(double col, double row) {
String t = getTileType(col, row);
return t.equalsIgnoreCase("impraticable");
}
public Set<Point> getBloc(int col, int row, CaseLister aCaseLister) {
String type = getTileType(col, row).toLowerCase();
if (!type.equals("donjon") && !type.equals("chateau"))
return Collections.emptySet();
Set<Point> visited = new HashSet<>();
Deque<Point> stack = new ArrayDeque<>();
stack.push(new Point(col, row));
while (!stack.isEmpty()) {
Point p = stack.pop();
if (visited.contains(p)) continue;
String t = getTileType(p.x, p.y).toLowerCase();
// Si la case est vide ou village, on l'arrête
if (t.equals("village") || t.equals("empty") || t.equals(""))
continue;
visited.add(p);
for (int[] n : aCaseLister.getNeighboringHexes(p.x, p.y)) {
String nt = getTileType(n[0], n[1]).toLowerCase();
// On ne traverse que donjon/château, pas village/empty
if (nt.equals("donjon") || nt.equals("chateau"))
stack.push(new Point(n[0], n[1]));
}
}
return visited;
}
/** 🔹 Charge le fichier TileType.txt et exécute les setTileType */
public void loadTileTypes() {
File f = new File("TileType.txt");
if (!f.exists()) {
System.out.println("⚠️ Aucun fichier TileType.txt trouvé.");
return;
}
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty() || line.startsWith("//")) continue;
// Ex : setTileType(10, 5, "donjon");
if (line.startsWith("setTileType(")) {
String inside = line.substring(line.indexOf('(') + 1, line.indexOf(')'));
String[] parts = inside.split(",");
if (parts.length == 3) {
double col = Integer.parseInt(parts[0].trim());
double row = Integer.parseInt(parts[1].trim());
String type = parts[2].trim().replace("\"", "");
setTileType(col, row, type);
}
}
}
System.out.println("✅ " + tileTypes.size() + " tuiles chargées depuis TileType.txt");
} catch (IOException e) {
System.err.println("❌ Erreur lecture TileType.txt : " + e.getMessage());
}
}
public Map<Point, String> getAllTiles() {
return tileTypes;
}
}