diff --git a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs index 9d293ffe6f4dad73bce2fdd2527e4b1a02afcfab..f349c60a6980e2ff80d74bcbcf6a6933bfdfa55b 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs @@ -119,7 +119,7 @@ namespace Controller for (int y=0; y<graph.getHeight(); y++) { // if a path exists to that node, add it to list of moveable nodes - if (pathFinder(graph, unit, currentNode, graph.getNode(x, y)) != null) { + if (pathFinder(graph, unit, currentNode, graph.getNode(x, y)) != null && !graph.getNode(x, y).isOccupied()) { moveableNodes.AddLast(graph.getNode(x, y)); } } diff --git a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs index 2724442f4a924bf80a7b507fd525e1e3bb90a4c7..5d1634c5db14ef1225b9497d6b9c763dc0f5d874 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs @@ -74,7 +74,7 @@ namespace Controller // if path finder returns a non-null path, then end node is valid if (path != null) { - updateUnitPosition(mouseClickCoordinates, path); + updateUnitPosition(graph, mouseClickCoordinates, path); } turnState = TurnState.Wait; @@ -124,14 +124,14 @@ namespace Controller } // update the unit's position to the clicked position - private static void updateUnitPosition(Vector2 position, LinkedList<Node> path) + private static void updateUnitPosition(Graph graph, Vector2 position, LinkedList<Node> path) { Unit unit = GameState.getSelectedUnit(); GameState.setIsAnimating(true); // updates the unit's position to each node in the path (node by node) foreach (Node node in path) { - animateUnitPosition(unit, node); + animateUnitPosition(graph, unit, node); GameState.setMenuOpen(true); } @@ -141,11 +141,13 @@ namespace Controller // TODO: move this function to animation class // animates unit to move to node - private static void animateUnitPosition(Unit unit, Node node) + private static void animateUnitPosition(Graph graph, Unit unit, Node node) { int nodePixelX = node.getPositionX() * 32; int nodePixelY = node.getPositionY() * 32; + graph.getNode(unit.getPosition()).setUnitOnNode(null); + while (unit.getPixelCoordinates().X != nodePixelX) { if (unit.getPixelCoordinates().X < nodePixelX) @@ -177,6 +179,8 @@ namespace Controller Thread.Sleep(40); } } + + node.setUnitOnNode(unit); } // returns a menu button that was clicked; if no menu button was clicked, returns null diff --git a/src/Blaze-Brigade/Blaze_Brigade/Node.cs b/src/Blaze-Brigade/Blaze_Brigade/Node.cs index f73cf694dfc55dfdd476cbabc438fdab9f9dfaca..c092b35a936f0321b0decbcd2674cc7df8226b26 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Node.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Node.cs @@ -10,6 +10,7 @@ namespace Model { private int movabilityObstruction; // index for hindrance of the movability of a unit; 0 = no hindrance private bool isObstacle; // indicates whether a unit can stand inside the tile + private Unit unitOnNode; // holds the unit that is on the node private int positionX; // position x on the grid private int positionY; // position y on the grid @@ -56,5 +57,25 @@ namespace Model { return positionY; } + + public Unit getUnitOnNode() + { + return unitOnNode; + } + + public void setUnitOnNode(Unit unit) + { + unitOnNode = unit; + } + + // indicates whether node is occupied by a unit + public bool isOccupied() + { + if (unitOnNode != null) + { + return true; + } + return false; + } } }