From d5aee9df084168e9b6ab4e4707bb188ddd3cb7ea Mon Sep 17 00:00:00 2001
From: trandit <trandit@mcmaster.ca>
Date: Wed, 2 Nov 2016 10:29:40 -0400
Subject: [PATCH] Update highlighted attack nodes to show correct attackable
 nodes after moving. Cleaned up unused methods

---
 src/Blaze-Brigade/Blaze_Brigade/Game.cs        | 15 ++++++++++-----
 .../Blaze_Brigade/GameFunction.cs              | 18 ++++++++++++++++++
 src/Blaze-Brigade/Blaze_Brigade/GameState.cs   |  4 ++++
 .../Blaze_Brigade/MouseHandler.cs              |  8 ++------
 src/Blaze-Brigade/Blaze_Brigade/Unit.cs        |  2 --
 src/Blaze-Brigade/Blaze_Brigade/Warrior.cs     | 12 ------------
 6 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs
index 2dc60ca..5895886 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs
@@ -207,17 +207,17 @@ namespace Controller
                         {
 
 
-                            if (GameState.getBeforeMove())
+                            if (GameState.getBeforeMove()) // if unit has yet to move, display the overall move and attack range of unit
                             {
                             #region Highlight nodes
-                            //Highlight movable nodes in blue
+                            // Highlight movable nodes in blue
                             LinkedList<Node> moveableNodes = GameFunction.getMovableNodes(graph, unit);
                             foreach (Node move in moveableNodes)
                             {
                                 spriteBatch.Draw(moveableNode, move.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
                             }
 
-                            //Highlight attackable nodes in red
+                            // Highlight attackable nodes in red
                             LinkedList<Node> attackableNodes = GameFunction.getAttackableNodes(graph, unit);
                             foreach (Node attack in attackableNodes)
                             {
@@ -227,9 +227,14 @@ namespace Controller
                                 }
                             }
                                 #endregion
-                            }else
+                            }
+                            else // elseif unit has already moved, only display the attack range
                             {
-
+                                LinkedList<Node> attackableNodes = GameFunction.getAttackRangeAfterMoving(graph, unit);
+                                foreach (Node attack in attackableNodes)
+                                {
+                                        spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
+                                }
                             }
 
                             #region Drop Down menu
diff --git a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
index 2afc970..2f243df 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
@@ -130,6 +130,24 @@ namespace Controller
             return attackableNodes;
         }
 
+        public static LinkedList<Node> getAttackRangeAfterMoving(Graph graph, Unit unit)
+        {
+            LinkedList<Node> attackableNodes = new LinkedList<Node>();
+            Tuple<int, int> currentPosition = unit.getPosition();
+            for (int x = 0; x < graph.getWidth(); x++)
+            {
+                for (int y = 0; y < graph.getHeight(); y++)
+                {
+                    if (isNodeAttackable(unit.getClass(), currentPosition.Item1, currentPosition.Item2, graph.getNode(x, y)))
+                    {
+                        // if node is attackable, add it to list of attackable nodes
+                        attackableNodes.AddLast(graph.getNode(x, y));
+                    }
+                }
+            }
+            return attackableNodes;
+        }
+
         // returns list of nodes representing the path from start node to end node; if no path is valid, return null
         public static LinkedList<Node> pathFinder(Graph graph, Unit unit, Node start, Node end)
         {
diff --git a/src/Blaze-Brigade/Blaze_Brigade/GameState.cs b/src/Blaze-Brigade/Blaze_Brigade/GameState.cs
index 1fff4ed..358b808 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/GameState.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/GameState.cs
@@ -62,21 +62,25 @@ namespace Model
             isAnimating = animating;
         }
 
+        // sets if the dropDownMenu is currently opened
         public static void setMenuOpen(bool isOpen)
         {
             dropDownMenuOpen = isOpen;
         }
 
+        // returns if the dropdownmenu is currently opened
         public static bool getMenuOpen()
         {
             return dropDownMenuOpen;
         }
 
+        //sets determines if the unit is preparing to move, or already moved
         public static void setBeforeMove(bool hasMove)
         {
             beforeMove = hasMove;
         }
 
+        //returns whether the unit has moved
         public static bool getBeforeMove()
         {
             return beforeMove;
diff --git a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs
index e529e99..45b8493 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/MouseHandler.cs
@@ -65,7 +65,6 @@ namespace Controller
                     if (turnState == TurnState.Move)
                     {
                         // remove drop down menu from screen
-                        GameState.getSelectedUnit().setMenuOpen(false);
                         Game.Instance.Tick();
 
                         // set variables for path finding
@@ -79,7 +78,7 @@ namespace Controller
                             updateUnitPosition(mouseClickCoordinates, path);
                         }
 
-                        GameState.getSelectedUnit().setMenuOpen(true);      // opens drop down menu on screen again
+
                         turnState = TurnState.Wait;
                     }
                 }
@@ -103,10 +102,7 @@ namespace Controller
         // sets selection of unit state inside GameFunction and the unit itself
         private static void setSelectedUnit(Unit unit, bool selected)
         {
-            if (unit != null)
-            {
-                unit.setMenuOpen(selected);
-            }
+
             GameState.setPlayableUnitSelected(selected);
             GameState.setSelectedUnit(unit);
         }
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Unit.cs b/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
index 4a5c897..1309cdc 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
@@ -36,8 +36,6 @@ namespace Model
         void setPosition(int x, int y);         // sets the current position (by node) of the unit
         void setEquippedWeapon(Weapon w);       // sets the unit's currently equipped weapon
         void setMoved(bool a);                  // on start of players turn, set all units to unmoved (F)
-        void setMenuOpen(bool a);               // Sets if the dropdown menu should be opened
-        bool getMenuOpen();                     // returns if the dropdown menu should be open
         MenuButton[] getMenuButtons();          // returns the dropdown menu buttons of the unit
     }
 
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
index 9fb6ca6..981c0fa 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
@@ -204,18 +204,6 @@ namespace Model
             this.moved = a;
         }
 
-        // set if menu should be open
-        public void setMenuOpen(bool a)
-        {
-            menuOpen = a;
-        }
-
-        // return if menu has been open
-        public Boolean getMenuOpen()
-        {
-            return menuOpen;
-        }
-
         public MenuButton[] getMenuButtons()
         {
             return menuButtons;
-- 
GitLab