/** * Handle the mouse being pressed. If the mouse is over a unit select it. Otherwise we move the * selected unit to the new target (assuming there was a path found) * * @param x The x coordinate of the mouse cursor on the screen * @param y The y coordinate of the mouse cursor on the screen */ public void PosicioInicial(int x, int y, int option) { // System.out.println("Posicio Inicial "+x+" "+y); if ((x < 0) || (y < 0) || (x >= map.getWidthInTiles()) || (y >= map.getHeightInTiles())) { return; } if (map.getUnit(x, y) != 0) { selectedx = x; selectedy = y; lastFindX = -1; } else { // if (true){ map.clearVisited(); path = finder.findPath( new UnitMover(map.getUnit(selectedx, selectedy)), selectedx, selectedy, x, y, option); if (path != null) { path = null; int unit = map.getUnit(selectedx, selectedy); map.setUnit(selectedx, selectedy, 0); map.setUnit(x, y, unit); selectedx = x; selectedy = y; lastFindX = -1; } // } } // System.out.printf("Selected: "+selectedx+" "+selectedy); }
// TENIR EN COMPTE K SERA UN STREET public Path PosicioFinal(int x, int y, int option) { // if (true) { // D'acord l'algoritme la posicio final interve en el calcul! per a k sigui possible la // convertime temporalment en una // posicio accesible(STREET) map.setTerrain(x, y); if ((lastFindX != x) || (lastFindY != y)) { lastFindX = x; lastFindY = y; path = finder.findPath( new UnitMover(map.getUnit(selectedx, selectedy)), selectedx, selectedy, x, y, option); } // } return path; }
public static void main(String[] args) { Map<Character, ImmutableGraphNode<Character>> graph = GraphFactory.createSimpleGraph(); printPath( AStarPathFinder.findPath(graph.get('A'), graph.get('D'), new MyNodeExpander<Character>())); }