diff --git a/Assets/Scripts/Squad.cs b/Assets/Scripts/Squad.cs new file mode 100644 index 0000000..6af56a3 --- /dev/null +++ b/Assets/Scripts/Squad.cs @@ -0,0 +1,95 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +public class Squad : Unit +{ + /// + /// List of non attackable units. + /// + private List humans; + /// + /// List of attackable units. + /// + private List soldiers; + + // Use this for initialization + void Start () + { + humans = new List(); + soldiers = new List(); + } + + // Update is called once per frame + void Update () + { + // TODO execute movement command + // TODO Check if all the units are dead + // if yes destroy + if (soldiers.Count == 0) + { + // then we destroy the squad + DestroyUnit(); + } + } + + void addHuman(Unit humanUnit) + { + humans.Add(humanUnit); + } + + void addSoldier(Unit soldierUnit) + { + soldiers.Add(soldierUnit); + } + + /// + /// Dispose of a human unit and heal all the soldiers with a percentage depending + /// of the number of remaining soldiers. + /// + /// The human to dispose + void healSquad(Unit humanUnit ) + { + + var percentageOfHpToHeal = ( humanUnit.Hp / soldiers.Count ); + + foreach (var soldier in soldiers) + { + soldier.Hp += soldier.Hp * ( 1 + percentageOfHpToHeal ); + } + + // dispose of the human unit + removeHuman(humanUnit); + } + + /// + /// Abandon a specified amount of units. + /// + /// The number of units to abandon + void AbandonUnits(int nbUnits) + { + humans.RemoveRange(0,nbUnits); + } + + /// + /// Remove the selected soldier from the unit list. + /// + /// the corresponding soldier that we want to remove + void removeSoldier(Unit soldierUnit) + { + soldiers.Remove(soldierUnit); + } + + /// + /// Remove the selected human from the human list. + /// + /// the corresponding human that we want to remove + void removeHuman(Unit humanUnit) + { + humans.Remove(humanUnit); + } + + void transformHuman() + { + + } +} diff --git a/Assets/Scripts/Squad.cs.meta b/Assets/Scripts/Squad.cs.meta new file mode 100644 index 0000000..d852a36 --- /dev/null +++ b/Assets/Scripts/Squad.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 03db9d7aaef4ee545971f18bb90ceadb +timeCreated: 1439412250 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit.cs b/Assets/Scripts/Unit.cs index b15de44..c7ffcfd 100644 --- a/Assets/Scripts/Unit.cs +++ b/Assets/Scripts/Unit.cs @@ -9,17 +9,17 @@ public class Unit : MonoBehaviour private LinkedList commandList; public int defaultHp = 250; public int defaultAttack = 100; - + private int _hp; // the unit hp // Use this for initialization void Start () { // initialize default hp - //Hp = defaultHp; + Hp = defaultHp; // initialize default attack Attack = defaultAttack; // initialize default team // initialize default specie - isDead = false; + IsDead = false; } /// @@ -41,17 +41,39 @@ public class Unit : MonoBehaviour /// protected void DestroyUnit() { + //TODO First play dead animation + // then destroy the game object Destroy(this.transform.gameObject); } #region Unit properties - public int Hp { get; set; } + public int Hp + { + get { return _hp; } + + set + { + if (Hp < 0) + { + _hp = 0; + IsDead = true; + } + else if (value > defaultHp) + { + _hp = defaultHp; + } + else + { + _hp = value; + } + } + } public int Attack { get; set; } //public bool isAlly { get; set; } //public bool isHuman { get; set; } - public bool isDead { get; set; } + public bool IsDead { get; set; } public String Tag { diff --git a/Assets/Scripts/VampireUnit.cs b/Assets/Scripts/VampireUnit.cs index 8de8360..dcf5722 100644 --- a/Assets/Scripts/VampireUnit.cs +++ b/Assets/Scripts/VampireUnit.cs @@ -17,13 +17,13 @@ public class VampireUnit : Unit Attack = defaultAttack; // initialize default team // initialize default specie - isDead = false; + IsDead = false; } // Update is called once per frame void Update () { - if (isDead) + if (IsDead) { // TODO play dead animation before destroying unit DestroyUnit(); @@ -58,17 +58,10 @@ public class VampireUnit : Unit void AttackEnemy(Unit unit) { //TODO improve this method to compute the reduce of hp, etc... - if (unit.Hp <= 0) - { - unit.isDead = true; - } - else - { - // compute the amount of hp reduced to this unit - unit.Hp -= Attack; // we remove some hp of the unit that was + // compute the amount of hp reduced to this unit + unit.Hp -= Attack; // we remove some hp of the unit that was - Debug.Log("Attacked the ennemy : " + unit.Tag); - } + Debug.Log("Attacked the ennemy : " + unit.Tag); } void OnTriggerEnter(Collider collider) diff --git a/Assets/Scripts/ZombieUnit.cs b/Assets/Scripts/ZombieUnit.cs index bacbdcd..0cccd59 100644 --- a/Assets/Scripts/ZombieUnit.cs +++ b/Assets/Scripts/ZombieUnit.cs @@ -17,13 +17,13 @@ public class ZombieUnit : Unit Attack = defaultAttack; // initialize default team // initialize default specie - isDead = false; + IsDead = false; } // Update is called once per frame void Update() { - if (isDead) + if (IsDead) { // TODO play dead animation before destroying unit DestroyUnit(); @@ -56,17 +56,11 @@ public class ZombieUnit : Unit } void AttackEnemy(Unit unit) { - if (unit.Hp <= 0) - { - unit.isDead = true; - } - else - { - // compute the amount of hp reduced to this unit - unit.Hp -= Attack; // we remove some hp of the unit that was + + // compute the amount of hp reduced to this unit + unit.Hp -= Attack; // we remove some hp of the unit that was - Debug.Log("Attacked the ennemy : " + unit.Tag); - } + Debug.Log("Attacked the ennemy : " + unit.Tag); } void OnTriggerEnter(Collider collider)