Czoko_Smieciarka/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/TrashCans/ATrashCan.cs

45 lines
1.2 KiB
C#
Raw Permalink Normal View History

2019-03-13 14:19:38 +01:00
using System;
2019-03-13 14:51:01 +01:00
namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
2019-03-13 14:19:38 +01:00
{
public abstract class ATrashCan
{
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
{
this.MaxVolume = maxVolume;
2019-03-13 15:31:33 +01:00
this.TypeOfGarbage = typeOfGarbage;
2019-03-13 14:19:38 +01:00
}
2019-03-13 15:31:33 +01:00
public ITypeOfGarbage TypeOfGarbage { get; }
2019-03-13 14:19:38 +01:00
public int MaxVolume { get;}
public AGarbage Garbage { get; private set; }
public int FillPercent
{
get { return Garbage.Volume / this.MaxVolume; }
}
2019-03-13 16:55:34 +01:00
public virtual bool AddGarbage(IGarbage garbage)
2019-03-13 14:19:38 +01:00
{
2019-03-13 15:31:33 +01:00
if (this.TypeOfGarbage != garbage.TypeOfGarbage)
2019-03-13 14:51:01 +01:00
throw new Exception("You cannot add up different type garbage!");
2019-03-13 14:19:38 +01:00
var newGarbage = this.Garbage + Garbage;
if (newGarbage.Volume > this.MaxVolume)
return false;
this.Garbage = newGarbage;
return true;
}
public virtual AGarbage TakeGarbage()
{
2019-03-13 14:51:01 +01:00
var result = (AGarbage)this.Garbage.Clone();
this.Garbage.Weight = 0;
2019-03-13 14:19:38 +01:00
return result;
}
}
}