From 47da281d750a5171969b88f4ba0a6abfa52e393c Mon Sep 17 00:00:00 2001
From: Susan Yuen <susan_loves_cheese@hotmail.com>
Date: Fri, 11 Nov 2016 21:58:06 -0500
Subject: [PATCH] Adding unit death

---
 .../Blaze_Brigade/Blaze_Brigade.csproj        |  3 +-
 .../Blaze_Brigade.csproj.Debug.cachefile      |  4 +-
 src/Blaze-Brigade/Blaze_Brigade/Game.cs       | 38 ++++++++++++++++---
 .../Blaze_Brigade/GameFunction.cs             | 33 +++++++++++++---
 src/Blaze-Brigade/Blaze_Brigade/Player.cs     |  9 +++++
 src/Blaze-Brigade/Blaze_Brigade/Unit.cs       |  2 +-
 src/Blaze-Brigade/Blaze_Brigade/Warrior.cs    | 28 ++++++++++++--
 7 files changed, 99 insertions(+), 18 deletions(-)

diff --git a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj
index e1a4dc2..09218cb 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj
+++ b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj
@@ -31,7 +31,8 @@
     <UseVSHostingProcess>false</UseVSHostingProcess>
     <PlatformTarget>x86</PlatformTarget>
     <XnaCompressContent>false</XnaCompressContent>
-    <DocumentationFile>C:\Users\chaos\Documents\Blaze-Brigade\Doc\MIS\Blaze_Brigade.XML</DocumentationFile>
+    <DocumentationFile>
+    </DocumentationFile>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <DebugType>pdbonly</DebugType>
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile
index a9d64d0..22ddb42 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile
+++ b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile
@@ -6,10 +6,10 @@ Content\attack.xnb
 Content\items.xnb
 Content\move.xnb
 Content\wait.xnb
-Content\warrior_stats.xnb
-Content\warrior.xnb
 Content\PixelFont.xnb
+Content\warrior_stats.xnb
 Content\PixelFontLarge.xnb
+Content\warrior.xnb
 Content\instructions1.xnb
 Content\instructions2.xnb
 Content\instructions3.xnb
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs
index 6c132c5..eddcee4 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs
@@ -221,6 +221,16 @@ namespace Controller
 
                 case GameMenuState.Playing: // if true.. load new image...
                     backGround = Content.Load<Texture2D>("Game_Map"); // load background
+
+                    Debug.WriteLine(player1.getNumOfUnits());
+
+                    if (GameFunction.isGameOver(player1, player2))
+                    {
+                        // TODO: game over screen
+                        Debug.WriteLine("Game is over.");
+                        break;
+                    }
+
                     if (GameFunction.isTurnOver())
                     {
                         Player tempPlayer = GameState.currentPlayer;
@@ -228,6 +238,18 @@ namespace Controller
                         GameState.enemyPlayer = (tempPlayer);
                         GameFunction.startTurn(GameState.currentPlayer);
                     }
+
+                    // removes deceased units in Player 1
+                    foreach(Unit unit in player1.getUnits())
+                    {
+                        GameFunction.removeDeceasedUnit(graph, player1, unit);
+                    }
+
+                    // removes deceased units in Player 2
+                    foreach (Unit unit in player2.getUnits())
+                    {
+                        GameFunction.removeDeceasedUnit(graph, player2, unit);
+                    }
                     break;
             }
             #endregion
@@ -251,8 +273,11 @@ namespace Controller
                     for (int i = 0; i < player1.getNumOfUnits(); i++)
                     {
                         Unit unit = player1.getUnits().ElementAt(i); //gets unit at i
-                        spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
-                            unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
+                        if (unit.Alive)
+                        {
+                            spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
+                                unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
+                        }
                     }
                     #endregion
 
@@ -261,8 +286,11 @@ namespace Controller
                     for (int i = 0; i < player2.getNumOfUnits(); i++)
                     {
                         Unit unit = player2.getUnits().ElementAt(i);
-                        spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
-                            unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
+                        if (unit.Alive)
+                        {
+                            spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
+                                unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
+                        }
                     }
                     #endregion
 
@@ -435,7 +463,7 @@ namespace Controller
                     break;
             }
 
-            spriteBatch.End();  // end spriteBatch
+            spriteBatch.End();      // end spriteBatch
             base.Draw(gameTime);    // repeatedly calls draw
         }
 
diff --git a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
index b824c03..5018405 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs
@@ -130,9 +130,20 @@ namespace Controller
         /**
         Returns whether or not the game is over, based off win conditions.
         */
-        public static bool isGameOver()
+        public static bool isGameOver(Player player1, Player player2)
         {
-            // TODO
+            // if player1 does not have anymore units, game is over
+            if (player1.getNumOfUnits() <= 0)
+            {
+                return true;
+            }
+
+            // if player2 does not have anymore units, game is over
+            if (player2.getNumOfUnits() <= 0)
+            {
+                return true;
+            }
+
             return false;
         }
 
@@ -257,7 +268,7 @@ namespace Controller
         }
 
         /**
-        Returns a list of nodes representing the path from start node to end node; if not path is valid, return null.
+        Returns a list of nodes representing the path from start node to end node; if no path is valid, return null.
             \param graph Graph representing the current game map.
             \param unit Unit to move.
             \param start Start Node of the path.
@@ -350,6 +361,18 @@ namespace Controller
 
             return adjacentNodes;
         }
-    }
-}
 
+        /**
+        Updates units based on their status (alive/dead). If dead, will remove the unit from the game. (Unit will be no longer active).
+            \param unit Unit to update status of.
+        */
+        public static void removeDeceasedUnit(Graph graph, Player player, Unit unit)
+        {
+            if (!unit.Alive)
+            {
+                graph.getNode(unit.Position).unitOnNode = null;
+                player.removeUnit(unit);
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Player.cs b/src/Blaze-Brigade/Blaze_Brigade/Player.cs
index 3af48d1..089104e 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Player.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Player.cs
@@ -62,6 +62,15 @@ namespace Model
         {
             ownedUnits.AddLast(unit);
         }
+
+        /**
+       Removes the specified unit from the player's units.
+            \param unit Unit to be removed.
+        */
+        public void removeUnit(Unit unit)
+        {
+            ownedUnits.Remove(unit);
+        }
     }
 }
 
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Unit.cs b/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
index 15a81e7..05f7f89 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Unit.cs
@@ -32,7 +32,7 @@ namespace Model
         /**
         Sets and returns a unit's HP
         */
-        int Hp { get; set; } 
+        int Hp { get; set; }
                                    
         /**
         Sets and returns a unit's Strength
diff --git a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
index 5493417..bf71a5f 100644
--- a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
+++ b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs
@@ -20,13 +20,12 @@ namespace Model
         Sets and returns whether or not unit is alive
         */
         public bool Alive { get; set; }
-        /**
-        Sets and returns a unit's HP
-        */
-        public int Hp { get; set; }     
+            
         private int str;                // unit strength
         private int intelligence;       // unit intelliegence
         private int skill;              // unit skill
+        private int hp;                 // unit hp
+
         /**
         Sets and returns a unit's Speed
         */
@@ -154,6 +153,27 @@ namespace Model
             }
         }
 
+        /*
+        Sets the hp of the unit.
+        \n Gets the unit's hp.
+        */
+        public int Hp
+        {
+            get
+            {
+                return hp;
+            }
+            set
+            {
+                if (value <= 0)
+                {
+                    this.Alive = false;
+                }
+
+                hp = value;
+            }
+        }
+
         /**
         Returns the unit's movability range on grid (number of spaces the unit can move in one turn)
         */
-- 
GitLab