| | | 1 | | namespace Safarimacik.Model; |
| | | 2 | | |
| | | 3 | | |
| | | 4 | | /// <summary> |
| | | 5 | | /// Base class for regenerating plants. |
| | | 6 | | /// </summary> |
| | | 7 | | public abstract class RegeneratingPlant(double nutrition, int cooldown, bool isRipe) : Plant(nutrition) { |
| | | 8 | | public readonly int Cooldown = cooldown; |
| | | 9 | | |
| | | 10 | | protected int _currentCooldown; |
| | | 11 | | protected bool _isRipe = isRipe; |
| | | 12 | | |
| | | 13 | | public event Action? StateChanged; |
| | | 14 | | |
| | | 15 | | public bool IsRipe => _isRipe; |
| | | 16 | | |
| | | 17 | | public void Consume() { |
| | | 18 | | _isRipe = false; |
| | | 19 | | _currentCooldown = Cooldown; |
| | | 20 | | StateChanged?.Invoke(); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public void DecreaseCurrentCooldown() { |
| | | 24 | | --_currentCooldown; |
| | | 25 | | if (_currentCooldown == 0) { |
| | | 26 | | _isRipe = true; |
| | | 27 | | StateChanged?.Invoke(); |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Represents a regenerating, placeable |
| | | 34 | | /// </summary> |
| | | 35 | | public class Tree : RegeneratingPlant, Purchasable { |
| | | 36 | | public const int Price = 80; |
| | | 37 | | public new const int Cooldown = 120; |
| | | 38 | | |
| | 1 | 39 | | int Purchasable.Price => Price; |
| | | 40 | | |
| | 1 | 41 | | public Tree() : base(50, Cooldown, true) { } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Represents a regenerating, placeable |
| | | 46 | | /// </summary> |
| | | 47 | | public class Bush : RegeneratingPlant, Purchasable { |
| | | 48 | | public const int Price = 115; |
| | | 49 | | public new const int Cooldown = 60; |
| | | 50 | | |
| | | 51 | | int Purchasable.Price => Price; |
| | | 52 | | |
| | | 53 | | public Bush() : base(60, Cooldown, true) { } |
| | | 54 | | } |