From c79bc4b4af5a8b0b82584ad2294de0107a3880e6 Mon Sep 17 00:00:00 2001 From: Jeremy Klotz <jeremyjklotz@hotmail.com> Date: Wed, 2 Nov 2016 16:20:28 -0400 Subject: [PATCH] Added weapon to unit when initialized, red squares / attackable nodes missing --- src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs | 2 +- .../Blaze_Brigade/BronzeSword.cs | 3 +- src/Blaze-Brigade/Blaze_Brigade/FireBall.cs | 2 +- src/Blaze-Brigade/Blaze_Brigade/Game.cs | 10 ++++-- .../Blaze_Brigade/GameFunction.cs | 31 +++++++------------ src/Blaze-Brigade/Blaze_Brigade/Warrior.cs | 7 +++-- src/Blaze-Brigade/Blaze_Brigade/Weapon.cs | 6 ++-- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs b/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs index b6215d5..5e1beb1 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/BronzeBow.cs @@ -34,7 +34,7 @@ namespace Model public int[] getRange() { - return range; + return range; } public int getSkill() diff --git a/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs b/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs index 99f0523..62f5bb2 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/BronzeSword.cs @@ -23,7 +23,6 @@ namespace Model modStr = 5; modSkill = 10; modInt = 0; - range = getRange(); range = new int[2]; range[0] = minRange; range[1] = maxRange; @@ -31,7 +30,7 @@ namespace Model public int[] getRange() { - return range; + return range; } public int getStrength() diff --git a/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs b/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs index 108723e..b6e5568 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/FireBall.cs @@ -38,7 +38,7 @@ namespace Model public int[] getRange() { - return range; + return range; } public int getSkill() diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs index b69eb86..38b9cfb 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs @@ -106,9 +106,13 @@ namespace Controller MenuButton moveButton = new MenuButton(MenuButtonType.Move, unit1Position, Content.Load<Texture2D>("move")); MenuButton itemButton = new MenuButton(MenuButtonType.Items, unit1Position, Content.Load<Texture2D>("items")); ; MenuButton waitButton = new MenuButton(MenuButtonType.Wait, unit1Position, Content.Load<Texture2D>("wait")); ; - - player1.addUnit(new Warrior(Content.Load<Texture2D>("charSprite"), attackButton, moveButton, - itemButton, waitButton, Content.Load<Texture2D>("warrior_Info"), unit1Position)); + + Weapon bsword = new BronzeSword(); + Warrior warrior1 = new Warrior(Content.Load<Texture2D>("charSprite"), attackButton, moveButton, + itemButton, waitButton, Content.Load<Texture2D>("warrior_Info"), unit1Position); + warrior1.setEquipableWeapons(bsword); + warrior1.setEquippedWeapon(bsword); + player1.addUnit(warrior1); GameState.setPlayerCurrentlyMoving(player1); // set game state } diff --git a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs index 44df1d2..f2a9eba 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/GameFunction.cs @@ -52,10 +52,13 @@ namespace Controller // checks if the node is attackable based on the unit's class and position // I THINK THIS WOULD WORK MUCH SIMPLER BASED ON EQUIPPED WEAPON NOT UNIT TYPE!! // IF logic < equippedweapon.range or IF logic < weapon with highest range. - private static bool isNodeAttackable(UnitType unitType, int unitX, int unitY, Node attackNode) + private static bool isNodeAttackable(Unit unit, Node attackNode) { + int unitX = unit.getPosition().Item1; + int unitY = unit.getPosition().Item2; int attackX = attackNode.getPositionX(); int attackY = attackNode.getPositionY(); + int[] range = unit.getEquippedWeapon().getRange(); if (attackNode.getIsObstacle()) { @@ -63,23 +66,12 @@ namespace Controller } // return warrior attackable nodes (one node away) - if (unitType == UnitType.Warrior && - Math.Abs(unitX - attackX) + Math.Abs(unitY - attackY) == 1) + for (int i = 0; i < range.Count(); i++) { - return true; - } - // return archer attackable nodes (two nodes away) - else if (unitType == UnitType.Archer && - Math.Abs(unitX - attackX) + Math.Abs(unitY - attackY) == 2) - { - return true; - } - // return mage attackable nodes (one node and two nodes away) - else if (unitType == UnitType.Mage && - (Math.Abs(unitX - attackX) + Math.Abs(unitY - attackY) == 1 || - Math.Abs(unitX - attackX) + Math.Abs(unitY - attackY) == 2)) - { - return true; + if (Math.Abs(unitX - attackX) + Math.Abs(unitY - attackY) == range[i]) + { + return true; + } } return false; @@ -119,8 +111,7 @@ namespace Controller { for (int y = 0; y < graph.getHeight(); y++) { - if (isNodeAttackable(unit.getClass(), moveableNode.getPositionX(), - moveableNode.getPositionY(), graph.getNode(x, y))) + if (isNodeAttackable(unit, graph.getNode(x, y))) { // if node is attackable, add it to list of attackable nodes attackableNodes.AddLast(graph.getNode(x, y)); @@ -139,7 +130,7 @@ namespace Controller { for (int y = 0; y < graph.getHeight(); y++) { - if (isNodeAttackable(unit.getClass(), currentPosition.Item1, currentPosition.Item2, graph.getNode(x, y))) + if (isNodeAttackable(unit, graph.getNode(x, y))) { // if node is attackable, add it to list of attackable nodes attackableNodes.AddLast(graph.getNode(x, y)); diff --git a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs index 58af361..ea0874f 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Warrior.cs @@ -50,6 +50,7 @@ namespace Model setMenuButtonCoordinates(pixelCoordinates); equipableWeapons = new Weapon[3]; + } public bool isAlive() @@ -232,11 +233,11 @@ namespace Model // if the weaqpon slot is empty, add the weapon public void setEquipableWeapons(Weapon add) { - - for (int i =0; i < this.equipableWeapons.GetLength(1); i++) + int length = this.equipableWeapons.Count(); + for (int i =0; i < length; i++) { Weapon current = equipableWeapons.ElementAt(i); - if (current != null) + if (current == null) { current = add; break; diff --git a/src/Blaze-Brigade/Blaze_Brigade/Weapon.cs b/src/Blaze-Brigade/Blaze_Brigade/Weapon.cs index fd22581..06a8be3 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Weapon.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Weapon.cs @@ -8,11 +8,13 @@ namespace Model interface Weapon { - + int[] getRange(); // get the range of the weapon, i believe that using Unit.equippedWeapon - // or weapon with largest range in inventory to determine attackable squares, as opposed to the unit itself. + + + int getStrength(); int getSkill(); int getInt(); -- GitLab