50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
|
{
|
|
public abstract class ATrashCan : ICloneable
|
|
{
|
|
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
|
|
{
|
|
this.MaxVolume = maxVolume;
|
|
this.TypeOfGarbage = typeOfGarbage;
|
|
}
|
|
|
|
public ITypeOfGarbage TypeOfGarbage { get; }
|
|
|
|
public int MaxVolume { get;}
|
|
|
|
public AGarbage Garbage { get; private set; }
|
|
|
|
public int FillPercent
|
|
{
|
|
get { return Garbage.Volume / this.MaxVolume; }
|
|
}
|
|
|
|
public virtual bool AddGarbage(IGarbage garbage)
|
|
{
|
|
if (this.TypeOfGarbage != garbage.TypeOfGarbage)
|
|
throw new Exception("You cannot add up different type garbage!");
|
|
|
|
var newGarbage = this.Garbage + Garbage;
|
|
if (newGarbage.Volume > this.MaxVolume)
|
|
return false;
|
|
|
|
this.Garbage = newGarbage;
|
|
return true;
|
|
}
|
|
|
|
public object Clone()
|
|
{
|
|
return this.MemberwiseClone();
|
|
}
|
|
|
|
public virtual AGarbage TakeGarbage()
|
|
{
|
|
var result = (AGarbage)this.Garbage.Clone();
|
|
this.Garbage.Weight = 0;
|
|
return result;
|
|
}
|
|
}
|
|
}
|