- Added Squad script (not done)

- Updated Unit Hp property
- Added functions
	- addHuman
	- AddSoldier
	- healSquad( unit humanUnit )
	- abandonUnits( int nbUnits )
	- removeHuman( Unit humanUnit )
	- removeSoldier( Unit soldierUnit )
	- transformHuman() (not done)
This commit is contained in:
Samuel 2015-08-12 18:50:11 -04:00
parent 581334cbc6
commit 280fd57c2b
5 changed files with 145 additions and 29 deletions

95
Assets/Scripts/Squad.cs Normal file
View File

@ -0,0 +1,95 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Squad : Unit
{
/// <summary>
/// List of non attackable units.
/// </summary>
private List<Unit> humans;
/// <summary>
/// List of attackable units.
/// </summary>
private List<Unit> soldiers;
// Use this for initialization
void Start ()
{
humans = new List<Unit>();
soldiers = new List<Unit>();
}
// 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);
}
/// <summary>
/// Dispose of a human unit and heal all the soldiers with a percentage depending
/// of the number of remaining soldiers.
/// </summary>
/// <param name="humanUnit">The human to dispose</param>
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);
}
/// <summary>
/// Abandon a specified amount of units.
/// </summary>
/// <param name="nbUnits">The number of units to abandon</param>
void AbandonUnits(int nbUnits)
{
humans.RemoveRange(0,nbUnits);
}
/// <summary>
/// Remove the selected soldier from the unit list.
/// </summary>
/// <param name="soldierUnit">the corresponding soldier that we want to remove</param>
void removeSoldier(Unit soldierUnit)
{
soldiers.Remove(soldierUnit);
}
/// <summary>
/// Remove the selected human from the human list.
/// </summary>
/// <param name="humanUnit">the corresponding human that we want to remove</param>
void removeHuman(Unit humanUnit)
{
humans.Remove(humanUnit);
}
void transformHuman()
{
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 03db9d7aaef4ee545971f18bb90ceadb
timeCreated: 1439412250
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,17 +9,17 @@ public class Unit : MonoBehaviour
private LinkedList<Command> 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;
}
/// <summary>
@ -41,17 +41,39 @@ public class Unit : MonoBehaviour
/// </summary>
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
{

View File

@ -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)

View File

@ -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)