From 64975b3f05b8855c409f9efd0ae881a49b8dd201 Mon Sep 17 00:00:00 2001 From: Thien Trandinh <trandit@mcmaster.ca> Date: Mon, 14 Nov 2016 22:09:26 -0500 Subject: [PATCH] Now displays what weapon is currently equipped. Fix bug where damage can be negative, and hit/crit rate outside of 0-100 range --- src/Blaze-Brigade/Blaze_Brigade/Archer.cs | 4 +- .../Blaze_Brigade/Blaze_Brigade.csproj | 5 ++- .../Blaze_Brigade.csproj.Debug.cachefile | 18 ++++---- .../Blaze_Brigade/BronzeSword.cs | 4 +- .../Blaze_Brigade/DamageCalculations.cs | 29 +++++++++++-- src/Blaze-Brigade/Blaze_Brigade/FireBall.cs | 4 +- src/Blaze-Brigade/Blaze_Brigade/FireBlast.cs | 39 ++++++++++++++++++ src/Blaze-Brigade/Blaze_Brigade/Game.cs | 21 ++++++---- src/Blaze-Brigade/Blaze_Brigade/IronSword.cs | 35 ++++++++++++++++ src/Blaze-Brigade/Blaze_Brigade/LongBow.cs | 41 +++++++++++++++++++ src/Blaze-Brigade/Blaze_Brigade/Mage.cs | 4 +- .../{BronzeBow.cs => ShortBow.cs} | 12 +++--- src/Blaze-Brigade/Blaze_Brigade/Warrior.cs | 2 +- 13 files changed, 179 insertions(+), 39 deletions(-) create mode 100644 src/Blaze-Brigade/Blaze_Brigade/FireBlast.cs create mode 100644 src/Blaze-Brigade/Blaze_Brigade/IronSword.cs create mode 100644 src/Blaze-Brigade/Blaze_Brigade/LongBow.cs rename src/Blaze-Brigade/Blaze_Brigade/{BronzeBow.cs => ShortBow.cs} (74%) diff --git a/src/Blaze-Brigade/Blaze_Brigade/Archer.cs b/src/Blaze-Brigade/Blaze_Brigade/Archer.cs index 351db93..610211f 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Archer.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Archer.cs @@ -391,7 +391,7 @@ namespace Model buttons[4].setPixelCoordinates(330, 120); for (int i = 5; i < 9; i++) { - buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 150), (int)(pixelCoordinates.Y + (i - 1 * 32))); + buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 160), (int)(pixelCoordinates.Y + (i * 32 - 96))); } } @@ -505,4 +505,4 @@ namespace Model #endregion } } -} +} \ No newline at end of file diff --git a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj index 2eb821d..d856eec 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj +++ b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj @@ -69,7 +69,10 @@ </ItemGroup> <ItemGroup> <Compile Include="Archer.cs" /> - <Compile Include="BronzeBow.cs" /> + <Compile Include="FireBlast.cs" /> + <Compile Include="IronSword.cs" /> + <Compile Include="LongBow.cs" /> + <Compile Include="ShortBow.cs" /> <Compile Include="BronzeSword.cs" /> <Compile Include="DamageCalculations.cs" /> <Compile Include="Fireball.cs" /> 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 022bec4..2b05cc6 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile +++ b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj.Debug.cachefile @@ -6,31 +6,31 @@ Content\attack.xnb Content\items.xnb Content\move.xnb Content\wait.xnb +Content\PixelFont.xnb +Content\warrior_stats.xnb +Content\PixelFontLarge.xnb Content\warrior.xnb Content\instructions1.xnb Content\instructions2.xnb Content\instructions3.xnb +Content\mage_stats.xnb +Content\archer_stats.xnb Content\archer.xnb Content\mage.xnb Content\2archer.xnb Content\2archer_attack.xnb +Content\2archer_stats.xnb Content\2mage.xnb Content\2mage_attack.xnb +Content\2mage_stats.xnb Content\2warrior.xnb Content\2warrior_attack.xnb +Content\2warrior_stats.xnb Content\archer_attack.xnb Content\mage_attack.xnb Content\warrior_attack.xnb Content\attack_confirm.xnb Content\confirm_attack.xnb -Content\archer_stats.xnb -Content\2archer_stats.xnb -Content\2mage_stats.xnb -Content\2warrior_stats.xnb -Content\mage_stats.xnb -Content\warrior_stats.xnb -Content\exit_game.xnb -Content\PixelFont.xnb -Content\PixelFontLarge.xnb Content\PixelFontLargest.xnb +Content\exit_game.xnb Content\Inventory_Button.xnb diff --git a/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs b/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs index fd81671..ddbfe47 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs @@ -14,8 +14,6 @@ namespace Model */ class BronzeSword : Weapon { - private int minRange; - private int maxRange; public int modStr { get; } public int modInt { get; } public int modSkill { get; } @@ -27,7 +25,7 @@ namespace Model */ public BronzeSword() { - modStr = 50; + modStr = 5; modSkill = 5; modInt = 0; range = new int[2] { 1, 1 }; diff --git a/src/Blaze-Brigade/Blaze_Brigade/DamageCalculations.cs b/src/Blaze-Brigade/Blaze_Brigade/DamageCalculations.cs index c8510bb..4f930ce 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/DamageCalculations.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/DamageCalculations.cs @@ -19,7 +19,12 @@ namespace Model public static int getDamageDealt(Unit attacker, Unit defender, bool physOrMagic){ if(physOrMagic== false) { - return attacker.Str - defender.Def; //return physical damage dealt + int damage = attacker.Str - defender.Def; + if (damage < 0)// to prevent attacks from healing if defense is higher then attack + { + damage = 0; + } + return damage; //return physical damage dealt } else { @@ -34,7 +39,15 @@ namespace Model */ public static int getHitRate(Unit attacker, Unit defender) { - return (int) Math.Round( ( ( (attacker.Skill / 10.0) - (defender.Skill / 10.0) + 1.0) * 0.8)*100.0); + int hitRate = (int)Math.Round((((attacker.Skill / 10.0) - (defender.Skill / 10.0) + 1.0) * 0.8) * 100.0); + if (hitRate > 100) //to prevent hit rate over 100% + { + hitRate = 100; + }else if (hitRate < 0) //to prevent hit rate under 0% + { + hitRate = 0; + } + return hitRate; } /** @@ -44,7 +57,17 @@ namespace Model */ public static int getCritRate(Unit attacker, Unit defender) { - return (int)Math.Round( ( ( (attacker.Skill / 3.0) - (defender.Skill / 3.0) + 1.0) * 0.1) * 100.0); + + int critRate = (int)Math.Round((((attacker.Skill / 3.0) - (defender.Skill / 3.0) + 1.0) * 0.1) * 100.0); + if (critRate > 100) //to prevent crit rate over 100% + { + critRate = 100; + } + else if (critRate < 0) //to prevent crit rate under 0% + { + critRate = 0; + } + return critRate; } /** diff --git a/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs b/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs index 219fa86..335e35e 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs @@ -15,8 +15,6 @@ namespace Model */ class Fireball : Weapon { - private int minRange; - private int maxRange; public int modStr { get; } public int modInt { get; } public int modSkill { get; } @@ -29,7 +27,7 @@ namespace Model public Fireball() { modStr = 1; - modSkill = 2; + modSkill = 5; modInt = 5; range = new int[2] { 1, 2 }; name = "Fireball"; diff --git a/src/Blaze-Brigade/Blaze_Brigade/FireBlast.cs b/src/Blaze-Brigade/Blaze_Brigade/FireBlast.cs new file mode 100644 index 0000000..e1d4818 --- /dev/null +++ b/src/Blaze-Brigade/Blaze_Brigade/FireBlast.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Model +{ + /// <summary> + /// Ranged Magical Weapon. + /// </summary> + + /** + * This class represents a magic based weapon. + * It implements the Weapon interface. + */ + class Fireblast : Weapon + { + public int modStr { get; } + public int modInt { get; } + public int modSkill { get; } + public string name { get; } + public int[] range { get; } + + /** + Constructs a Fireball. + */ + public Fireblast() + { + modStr = 1; + modSkill = 3; + modInt = 7; + range = new int[2] { 1, 2 }; + name = "Fireblast"; + } + } +} + + + diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs index 3c5d3bf..ac2cf58 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs @@ -393,9 +393,11 @@ namespace Controller spriteBatch.DrawString(largeFont, hitRate.ToString()+" %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit rate spriteBatch.DrawString(largeFont, critRate.ToString()+" %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws crit rate spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health + spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon spriteBatch.Draw(attackedUnit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for unit being attacked spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health + spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon if (GameFunction.isEnemyUnitInRange(graph, attackedUnit, unit)) { @@ -414,9 +416,12 @@ namespace Controller spriteBatch.DrawString(largeFont, hitRate.ToString()+" %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit rate spriteBatch.DrawString(largeFont, critRate.ToString()+" %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack crit rate spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health + spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon spriteBatch.Draw(unit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for current character spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health + spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon + if (GameFunction.isEnemyUnitInRange(graph, unit, attackedUnit)) { spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(700, 458), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws damage @@ -588,7 +593,7 @@ namespace Controller { Unit unit = new Warrior(Content.Load<Texture2D>("warrior"),unitButtons, Content.Load<Texture2D>("warrior_stats"), Content.Load<Texture2D>("warrior_attack"), unitPosition); Weapon startingWeap = new BronzeSword(); - Weapon startingWeap2 = new BronzeBow(); + Weapon startingWeap2 = new IronSword(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; @@ -600,7 +605,7 @@ namespace Controller { Unit unit = new Mage(Content.Load<Texture2D>("mage"),unitButtons, Content.Load<Texture2D>("mage_stats"), Content.Load<Texture2D>("mage_attack"), unitPosition); Weapon startingWeap = new Fireball(); - Weapon startingWeap2 = new BronzeBow(); + Weapon startingWeap2 = new Fireblast(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; @@ -611,8 +616,8 @@ namespace Controller if (unitType == UnitType.Archer) { Unit unit = new Archer(Content.Load<Texture2D>("archer"), unitButtons, Content.Load<Texture2D>("archer_stats"), Content.Load<Texture2D>("archer_attack"), unitPosition); - Weapon startingWeap = new BronzeBow(); - Weapon startingWeap2 = new BronzeSword(); + Weapon startingWeap = new ShortBow(); + Weapon startingWeap2 = new LongBow(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; @@ -628,7 +633,7 @@ namespace Controller { Unit unit = new Warrior(Content.Load<Texture2D>("2warrior"), unitButtons, Content.Load<Texture2D>("2warrior_stats"), Content.Load<Texture2D>("2warrior_attack"), unitPosition); Weapon startingWeap = new BronzeSword(); - Weapon startingWeap2 = new BronzeBow(); + Weapon startingWeap2 = new IronSword(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; @@ -640,7 +645,7 @@ namespace Controller { Unit unit = new Mage(Content.Load<Texture2D>("2mage"), unitButtons, Content.Load<Texture2D>("2mage_stats"), Content.Load<Texture2D>("2mage_attack"), unitPosition); Weapon startingWeap = new Fireball(); - Weapon startingWeap2 = new BronzeBow(); + Weapon startingWeap2 = new Fireblast(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; @@ -651,8 +656,8 @@ namespace Controller if (unitType == UnitType.Archer) { Unit unit = new Archer(Content.Load<Texture2D>("2archer"),unitButtons, Content.Load<Texture2D>("2archer_stats"), Content.Load<Texture2D>("2archer_attack"), unitPosition); - Weapon startingWeap = new BronzeBow(); - Weapon startingWeap2 = new BronzeBow(); + Weapon startingWeap = new ShortBow(); + Weapon startingWeap2 = new LongBow(); unit.equippedWeapon = startingWeap; unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap; unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2; diff --git a/src/Blaze-Brigade/Blaze_Brigade/IronSword.cs b/src/Blaze-Brigade/Blaze_Brigade/IronSword.cs new file mode 100644 index 0000000..c6cfdec --- /dev/null +++ b/src/Blaze-Brigade/Blaze_Brigade/IronSword.cs @@ -0,0 +1,35 @@ + + +using System; + +namespace Model +{ + /// <summary> + /// Melee Physical Weapon. + /// </summary> + + /** + * This class represents a melee weapon. + * It implements the Weapon interface. + */ + class IronSword : Weapon + { + public int modStr { get; } + public int modInt { get; } + public int modSkill { get; } + public string name { get; } + public int[] range { get; } + + /** + Constructs a Bronze Sword. + */ + public IronSword() + { + modStr = 7; + modSkill = 3; + modInt = 0; + range = new int[2] { 1, 1 }; + name = "Iron Sword"; + } + } +} diff --git a/src/Blaze-Brigade/Blaze_Brigade/LongBow.cs b/src/Blaze-Brigade/Blaze_Brigade/LongBow.cs new file mode 100644 index 0000000..026b5ad --- /dev/null +++ b/src/Blaze-Brigade/Blaze_Brigade/LongBow.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Model +{ + /// <summary> + /// Ranged physical Weapon. + /// </summary> + + /** + * This class represents a ranged weapon. + * It implements the Weapon interface. + */ + class LongBow : Weapon + { + private int minRange; + private int maxRange; + public int modStr { get; } + public int modInt { get; } + public int modSkill { get; } + public string name { get; } + public int[] range { get; } + + /** + Constructs a Long Bow. + */ + public LongBow() + { + modStr = 7; + modSkill = 8; + modInt = 0; + range = new int[2] { 2, 3 }; + name = "Long Bow"; + } + } +} + + + diff --git a/src/Blaze-Brigade/Blaze_Brigade/Mage.cs b/src/Blaze-Brigade/Blaze_Brigade/Mage.cs index a2e40fe..00c4ec8 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Mage.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Mage.cs @@ -391,7 +391,7 @@ namespace Model buttons[4].setPixelCoordinates(330, 120); for (int i = 5; i < 9; i++) { - buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 150), (int)(pixelCoordinates.Y + (i - 1 * 32))); + buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 160), (int)(pixelCoordinates.Y + (i * 32 - 96))); } } @@ -505,4 +505,4 @@ namespace Model #endregion } } -} +} \ No newline at end of file diff --git a/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs b/src/Blaze-Brigade/Blaze_Brigade/ShortBow.cs similarity index 74% rename from src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs rename to src/Blaze-Brigade/Blaze_Brigade/ShortBow.cs index ce396f1..4046eb6 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/ShortBow.cs @@ -13,10 +13,8 @@ namespace Model * This class represents a ranged weapon. * It implements the Weapon interface. */ - class BronzeBow : Weapon + class ShortBow : Weapon { - private int minRange; - private int maxRange; public int modStr { get; } public int modInt { get; } public int modSkill { get; } @@ -24,15 +22,15 @@ namespace Model public int[] range { get; } /** - Constructs a Bronze Bow. + Constructs a Short Bow. */ - public BronzeBow() + public ShortBow() { - modStr = 3; + modStr = 7; modSkill = 10; modInt = 0; range = new int[2] { 2, 2 }; - name = "Bronze Bow"; + name = "Short Bow"; } } } diff --git a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs index 098ce7f..c31d733 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs @@ -99,7 +99,7 @@ namespace Model Alive = true; Level = 1; Hp = 10; - Str = 7; + Str = 5; Int = 1; Skill = 6; Speed = 8; -- GitLab