Nantes Université

Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 56f72ce1 rédigé par Leo LEMAIRE's avatar Leo LEMAIRE
Parcourir les fichiers

TP3

parent 19b4e70c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package tube; package tube;
import java.util.List;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import tube.gui.TubeView; import tube.gui.TubeView;
...@@ -38,25 +40,37 @@ public class Control { ...@@ -38,25 +40,37 @@ public class Control {
* show an itinerary between two stations. * show an itinerary between two stations.
* ----------------------------------------------------------- * -----------------------------------------------------------
*/ */
public void showItinerary(int x, int y){ public void showItinerary(int x, int y){
String station=tv.findClosestStation(x,y); String station=tv.findClosestStation(x,y);
System.out.println("USER ACTION: station selection = "+station); System.out.println("USER ACTION: station selection = "+station);
TermList sel=new TermList(); TermList sel=new TermList();
if (begin==null) { if (begin==null) {
begin=station; begin=station;
sel.add(begin); sel.add(begin);
tv.show(sel); tv.show(sel);
} }
else if (end==null) { else if (end==null) {
end=station; end=station;
TermList selection=null; TermList selection=new TermList();
if (selection==null) {
JOptionPane.showMessageDialog(tv, "No path has been found."); Path path = new Path(net);
sel=null; List<String> fPath = path.getPath(begin, end);
begin=null;
end=null; if(fPath == null)
} selection = null;
tv.show(selection); else{
} for(String st : fPath){
} selection.add(st);
}
}
if (selection==null) {
JOptionPane.showMessageDialog(tv, "No path has been found.");
sel=null;
begin=null;
end=null;
}
tv.show(selection);
}
}
} }
...@@ -21,9 +21,11 @@ public class Path { ...@@ -21,9 +21,11 @@ public class Path {
for(Step step : net.steps){ for(Step step : net.steps){
String nextS = step.getNext(current); String nextS = step.getNext(current);
if(nextS == null) continue; if(nextS == null) continue;
if(!visited.contains(nextS)) continue; if(visited.contains(nextS)) continue;
double alpha = tbv.angle(nextS, current, goal); if(nextS.equals(goal)) return nextS;
double alpha = tbv.angle(current, nextS, goal);
if(alpha < angMin){ if(alpha < angMin){
System.out.println(nextS + ":" + alpha);
angMin = alpha; angMin = alpha;
next = nextS; next = nextS;
} }
...@@ -40,6 +42,7 @@ public class Path { ...@@ -40,6 +42,7 @@ public class Path {
System.out.println(current); System.out.println(current);
if(current.equals(end)) return visited; if(current.equals(end)) return visited;
String next = getNextStation(current, end, visited); String next = getNextStation(current, end, visited);
System.out.println(next);
if(next == null) return null; if(next == null) return null;
current = next; current = next;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter