diff --git a/src/Map.java b/src/Map.java index 7e8a6f9..3a96ab4 100644 --- a/src/Map.java +++ b/src/Map.java @@ -39,6 +39,63 @@ public class Map return new Point[] {start, end}; } + private boolean followPath(Point start, Point end) + { + // remettre à 0 la liste + pathMap.clear(); + + // positions + Point current = start; + Point previous = null; + + int[][] coord = { + {1, 0}, // haut + {-1, 0}, // bas + {0, -1}, // gauche + {0, 1} // droite + }; + + // sécurité pour éviter les boucles infinie + int step = 0; + int max = map.length * map[0].length; + for (; step < max; step++) + { + pathMap.add(current); + + if (current.equals(end)) + return true; + + boolean moved = false; + + for (int[] pos : coord) + { + int x = current.x + pos[0]; + int y = current.y + pos[1]; + + if ((x >= 0 || map[0].length > x) || (y >= 0 || map.length > y)) + { + Point next = new Point(x, y); + + if (next.equals(previous)) + continue; + + CircuitCell type = map[y][x].getType(); + if (type == CircuitCell.FINISH || type == CircuitCell.ROAD + || type == CircuitCell.YROAD) + { + previous = current; + current = next; + moved = true; + break; + } + } + } + // Si il est bloqué + if (!moved) break; + } + + return false; + } public Circuit getElement(int x, int y) {