Created
May 14, 2018 18:05
-
-
Save dresswithpockets/2e52d4b237c2797c7ae21870293ccb95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player : Actor, IHealthy, IAttacker | |
{ | |
public float MaxHealth { get; } | |
public float Health { get; private set; } | |
public float AttackDamage { get; private set; } | |
public void DealDamage(float damage) | |
{ | |
Health = Mathf.Clamp(Health - damage, 0f, MaxHealth); | |
if (Health == 0f) | |
{ | |
Die(); | |
} | |
} | |
public void Heal(float amount) | |
{ | |
Health = Mathf.Clamp(Health + amount, 0f, MaxHealth); | |
} | |
public void Die() | |
{ | |
// do some stuff | |
} | |
public void Attack(IHealthy target) | |
{ | |
target.DealDamage(AttackDamage); | |
} | |
} | |
interface IHealthy | |
{ | |
float MaxHealth { get; } | |
float Health { get; } | |
void DealDamage(float damage); | |
void Heal(float amount); | |
void Die(); | |
} | |
interface IAttacker | |
{ | |
float AttackDamage { get; } | |
void Attack(IHealthy target); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment