Added Crop, Farming&Harvesting functionality (no graphics yet!)
This commit is contained in:
parent
b9030174b6
commit
a3a81eeb2a
3 changed files with 101 additions and 3 deletions
44
Assets/Scripts/Crop.cs
Normal file
44
Assets/Scripts/Crop.cs
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,5 @@ namespace Tiles
|
||||||
Debug.Log(usable.ToString() + " used on " + this.ToString());
|
Debug.Log(usable.ToString() + " used on " + this.ToString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,68 @@
|
||||||
using UnityEngine;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using DefaultNamespace;
|
||||||
|
using Items;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Tiles
|
namespace Tiles
|
||||||
{
|
{
|
||||||
public class FarmlandTile : BaseTile
|
public class FarmlandTile : BaseTile
|
||||||
{
|
{
|
||||||
|
private Crop _crop;
|
||||||
|
private bool _hydrated;
|
||||||
|
|
||||||
public FarmlandTile() : base(Color.black)
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue