Untitled
unknown
plain_text
2 years ago
620 B
10
Indexable
public interface IUsableItem
{
public void Use(Player player);
}
public class HealthPotion : IUsableItem
{
public void Use(Player player)
{
player.health += 50;
}
}
public class SpeedPotion : IUsableItem
{
public void Use(Player player)
{
player.speed += 10f;
}
}
public class Player
{
public int health { get; set; }
public float speed { get; set; }
public void OnLeftClick()
{
UseItem(new HealthPotion());
}
public void OnRightClick()
{
UseItem(new SpeedPotion());
}
public void UseItem(IUsableItem item)
{
item.Use(this);
}
}Editor is loading...
Leave a Comment