Czoko_Smieciarka/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs
2019-04-23 11:24:07 +02:00

62 lines
1.9 KiB
C#

using System;
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.Garbage;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
{
public abstract class ATrashCan : ICloneable
{
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
{
this.MaxVolume = maxVolume;
this.TypeOfGarbage = typeOfGarbage;
Garbage = new BasicGarbage(typeOfGarbage, 0);
}
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
{
this.MaxVolume = maxVolume;
this.TypeOfGarbage = typeOfGarbage;
this.Garbage = garbage;
}
public ITypeOfGarbage TypeOfGarbage { get; }
public int MaxVolume { get;}
public AGarbage Garbage { get; private set; }
public double FillPercent
{
get { return ((double)Garbage.Volume) / this.MaxVolume; }
}
public virtual void AddGarbage(AGarbage garbage)
{
//if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType)
// throw new Exception("You cannot add up different type garbage!");
var newGarbage = this.Garbage + garbage;
//if (newGarbage.Volume > this.MaxVolume)
// throw new Exception("Trash overload");
this.Garbage = newGarbage;
return;
}
public virtual object Clone()
{
throw new NotImplementedException();
}
public virtual AGarbage TakeGarbage()
{
if (this.Garbage.Weight == 0)
throw new Exception("Pusty śmietnik matole");
var result = (AGarbage)this.Garbage.Clone();
this.Garbage.Weight = 0;
return result;
}
}
}