Untitled
unknown
plain_text
8 months ago
620 B
3
Indexable
Never
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); } }
Leave a Comment