diff --git a/Assets/Scripts/Crop.cs b/Assets/Scripts/Crop.cs new file mode 100644 index 0000000..a5231d1 --- /dev/null +++ b/Assets/Scripts/Crop.cs @@ -0,0 +1,44 @@ +namespace DefaultNamespace +{ + public class Crop + { + private const int DaysUntilFinished = 4; + + private bool _fullyGrown; + public bool FullyGrown => _fullyGrown; + + private bool _markedForDeletion; + public bool MarkedForDeletion => _markedForDeletion; + + private int _daysGrown; + + public Crop() + { + _fullyGrown = false; + _markedForDeletion = false; + _daysGrown = 0; + } + + private void Grow() + { + _daysGrown++; + } + + public void DayLightStep(bool hydrated) + { + if (_daysGrown >= DaysUntilFinished) + { + _fullyGrown = true; + } + + if (!hydrated) + { + _markedForDeletion = true; + } + else if (!_fullyGrown) + { + Grow(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tiles/BaseTile.cs b/Assets/Scripts/Tiles/BaseTile.cs index 0450179..7316396 100644 --- a/Assets/Scripts/Tiles/BaseTile.cs +++ b/Assets/Scripts/Tiles/BaseTile.cs @@ -37,7 +37,5 @@ namespace Tiles Debug.Log(usable.ToString() + " used on " + this.ToString()); return null; } - - } } \ No newline at end of file diff --git a/Assets/Scripts/Tiles/FarmlandTile.cs b/Assets/Scripts/Tiles/FarmlandTile.cs index 8304251..e2c7278 100644 --- a/Assets/Scripts/Tiles/FarmlandTile.cs +++ b/Assets/Scripts/Tiles/FarmlandTile.cs @@ -1,12 +1,68 @@ -using UnityEngine; +using System; +using System.Threading; +using DefaultNamespace; +using Items; +using UnityEngine; namespace Tiles { public class FarmlandTile : BaseTile { + private Crop _crop; + private bool _hydrated; + public FarmlandTile() : base(Color.black) { + _crop = null; + _hydrated = false; + } + + public new void DayLightStep() + { + if (_crop != null) + { + _crop.DayLightStep(_hydrated); + if (_crop.MarkedForDeletion) + { + _crop = null; + } + } + } + + public new BaseTile Clicked(UsableItem usable) + { + base.Clicked(usable); + + ItemContainer ic = ItemContainer.Instance; + + if (usable.id == ic.GetItemIdByName("Hoe")) + { + _hydrated = true; + } + if (usable.id == ic.GetItemIdByName("Wheat Seed") && _crop == null) + { + Plant(); + } + + if (usable.id == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown) + { + Harvest(); + } + + return null; + } + + private void Harvest() + { + // add wheat to inventory + _crop = null; + } + + private void Plant() + { + // wheatSeeds-- in inventory + _crop = new Crop(); } } } \ No newline at end of file