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

86 lines
2.5 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-05-13 18:15:48 +02:00
Garbage = new BasicGarbage((TypeOfGarbage)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-05-13 14:12:28 +02:00
public virtual bool AddGarbage(AGarbage garbage)
2019-03-13 14:19:38 +01:00
{
2019-04-23 11:24:07 +02:00
//if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType)
// throw new Exception("You cannot add up different type garbage!");
2019-05-14 19:55:00 +02:00
if (FillPercent == 1) return false;
2019-03-13 14:19:38 +01:00
2019-05-14 19:55:00 +02:00
if (this.Garbage.Volume + garbage.Volume > this.MaxVolume)
{
this.Garbage.Weight = this.MaxVolume;
garbage.Weight = (this.MaxVolume - this.Garbage.Volume);
return true;
} else
{
2019-03-13 14:19:38 +01:00
2019-05-14 19:55:00 +02:00
var newGarbage = this.Garbage + garbage;
if (newGarbage.Volume > this.MaxVolume)
return false;
this.Garbage = newGarbage;
return true;
}
2019-04-23 06:32:35 +02:00
}
2019-05-14 19:55:00 +02:00
2019-04-23 06:32:35 +02:00
public virtual object Clone()
{
throw new NotImplementedException();
2019-03-13 14:19:38 +01:00
}
2019-05-14 19:55:00 +02:00
public virtual AGarbage TakeGarbage(double maxVolume)
2019-03-13 14:19:38 +01:00
{
2019-05-13 14:12:28 +02:00
2019-04-23 06:32:35 +02:00
if (this.Garbage.Weight == 0)
2019-05-13 14:12:28 +02:00
return null;
2019-05-14 19:55:00 +02:00
if (this.Garbage.Volume > maxVolume)
{
var result = (AGarbage)this.Garbage.Clone();
result.Weight = maxVolume;
this.Garbage.Weight = this.Garbage.Weight - maxVolume;
return result;
} else
{
var result = (AGarbage)this.Garbage.Clone();
this.Garbage.Weight = 0;
return result;
}
2019-03-13 14:19:38 +01:00
}
}
}