Czoko_Smieciarka/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs

62 lines
1.9 KiB
C#
Raw Normal View History

2019-03-13 14:19:38 +01:00
using System;
2019-04-23 06:32:35 +02:00
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.Garbage;
2019-03-13 14:19:38 +01:00
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
2019-03-13 14:19:38 +01:00
{
2019-04-23 06:32:35 +02:00
public abstract class ATrashCan : ICloneable
2019-03-13 14:19:38 +01:00
{
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
{
this.MaxVolume = maxVolume;
2019-03-13 15:31:33 +01:00
this.TypeOfGarbage = typeOfGarbage;
2019-04-23 06:32:35 +02:00
Garbage = new BasicGarbage(typeOfGarbage, 0);
2019-03-13 14:19:38 +01:00
}
2019-04-08 16:43:52 +02:00
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
{
this.MaxVolume = maxVolume;
this.TypeOfGarbage = typeOfGarbage;
this.Garbage = garbage;
}
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; }
2019-04-23 06:32:35 +02:00
public double FillPercent
2019-03-13 14:19:38 +01:00
{
2019-04-23 06:32:35 +02:00
get { return ((double)Garbage.Volume) / this.MaxVolume; }
2019-03-13 14:19:38 +01:00
}
2019-04-23 06:32:35 +02:00
public virtual void AddGarbage(AGarbage garbage)
2019-03-13 14:19:38 +01:00
{
2019-04-23 06:32:35 +02:00
if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType)
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
2019-04-23 06:32:35 +02:00
var newGarbage = this.Garbage + garbage;
2019-03-13 14:19:38 +01:00
if (newGarbage.Volume > this.MaxVolume)
2019-04-23 06:32:35 +02:00
throw new Exception("Trash overload");
2019-03-13 14:19:38 +01:00
this.Garbage = newGarbage;
2019-04-23 06:32:35 +02:00
return;
}
public virtual object Clone()
{
throw new NotImplementedException();
2019-03-13 14:19:38 +01:00
}
public virtual AGarbage TakeGarbage()
{
2019-04-23 06:32:35 +02:00
if (this.Garbage.Weight == 0)
throw new Exception("Pusty śmietnik matole");
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;
}
}
}