Skip to content

Instantly share code, notes, and snippets.

@dresswithpockets
Created May 14, 2018 18:05
Show Gist options
  • Save dresswithpockets/2e52d4b237c2797c7ae21870293ccb95 to your computer and use it in GitHub Desktop.
Save dresswithpockets/2e52d4b237c2797c7ae21870293ccb95 to your computer and use it in GitHub Desktop.
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