Dodano stepy
This commit is contained in:
parent
e89d892f79
commit
d6357bb13e
@ -41,6 +41,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Interfaces\Enums\Directions.cs" />
|
||||||
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
||||||
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
|
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
|
||||||
<Compile Include="Interfaces\Garbage\AGarbage.cs" />
|
<Compile Include="Interfaces\Garbage\AGarbage.cs" />
|
||||||
@ -50,8 +51,11 @@
|
|||||||
<Compile Include="Interfaces\RoutePlanningEngine\IRoutePlanningEngine.cs" />
|
<Compile Include="Interfaces\RoutePlanningEngine\IRoutePlanningEngine.cs" />
|
||||||
<Compile Include="Interfaces\TrashCans\AGarbageCollectorContainer.cs" />
|
<Compile Include="Interfaces\TrashCans\AGarbageCollectorContainer.cs" />
|
||||||
<Compile Include="Interfaces\TrashCans\ATrashCan.cs" />
|
<Compile Include="Interfaces\TrashCans\ATrashCan.cs" />
|
||||||
|
<Compile Include="Interfaces\TrashCans\IStep.cs" />
|
||||||
<Compile Include="Models\Coords.cs" />
|
<Compile Include="Models\Coords.cs" />
|
||||||
<Compile Include="Models\Map.cs" />
|
<Compile Include="Models\Map.cs" />
|
||||||
|
<Compile Include="Models\Steps\CollectStep.cs" />
|
||||||
|
<Compile Include="Models\Steps\MoveStep.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Interfaces.Enums
|
||||||
|
{
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down
|
||||||
|
}
|
||||||
|
}
|
@ -37,10 +37,5 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
||||||
|
|
||||||
public bool Collect(ITypeOfGarbage typeOfGarbage)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,5 @@ namespace CzokoŚmieciarka.DataModels.Interfaces
|
|||||||
Coords MoveRight();
|
Coords MoveRight();
|
||||||
|
|
||||||
IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
||||||
|
|
||||||
bool Collect(ITypeOfGarbage typeOfGarbage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,12 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
|
|
||||||
namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine
|
namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine
|
||||||
{
|
{
|
||||||
public abstract class ARoutePlanningEngine
|
public interface IRoutePlanningEngine
|
||||||
{
|
{
|
||||||
protected IGarbageCollector garbageCollector;
|
IEnumerable<IStep> CalculateStep();
|
||||||
|
|
||||||
protected IEnumerable<IGarbageLocalization> garbageLocalizations;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
|||||||
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
|
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume)
|
||||||
{
|
{
|
||||||
this.MaxVolume = maxVolume;
|
this.MaxVolume = maxVolume;
|
||||||
this._typeOfGarbage = typeOfGarbage;
|
this.TypeOfGarbage = typeOfGarbage;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ITypeOfGarbage _typeOfGarbage;
|
public ITypeOfGarbage TypeOfGarbage { get; }
|
||||||
|
|
||||||
public int MaxVolume { get;}
|
public int MaxVolume { get;}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
|||||||
|
|
||||||
public virtual bool AddGarbage(AGarbage garbage)
|
public virtual bool AddGarbage(AGarbage garbage)
|
||||||
{
|
{
|
||||||
if (this._typeOfGarbage != garbage.TypeOfGarbage)
|
if (this.TypeOfGarbage != garbage.TypeOfGarbage)
|
||||||
throw new Exception("You cannot add up different type garbage!");
|
throw new Exception("You cannot add up different type garbage!");
|
||||||
|
|
||||||
var newGarbage = this.Garbage + Garbage;
|
var newGarbage = this.Garbage + Garbage;
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
||||||
|
{
|
||||||
|
public interface IStep
|
||||||
|
{
|
||||||
|
void Invoke();
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,14 @@ namespace CzokoŚmieciarka.DataModels.Models
|
|||||||
public int X { get; set; }
|
public int X { get; set; }
|
||||||
public int Y { get; set; }
|
public int Y { get; set; }
|
||||||
|
|
||||||
|
public static bool operator == (Coords a, Coords b)
|
||||||
|
{
|
||||||
|
return a.X == b.X && a.Y == b.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Coords a, Coords b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Models.Steps
|
||||||
|
{
|
||||||
|
public class CollectStep : IStep
|
||||||
|
{
|
||||||
|
public CollectStep(IGarbageCollector garbageCollector, IGarbageLocalization garbageLocalization, ITypeOfGarbage typeOfGarbage)
|
||||||
|
{
|
||||||
|
this._garbageCollector = garbageCollector;
|
||||||
|
this._garbageLocalization = garbageLocalization;
|
||||||
|
this._typeOfGarbage = typeOfGarbage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IGarbageCollector _garbageCollector;
|
||||||
|
private ITypeOfGarbage _typeOfGarbage;
|
||||||
|
private IGarbageLocalization _garbageLocalization;
|
||||||
|
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
if(_garbageCollector.Position != _garbageLocalization.Coords)
|
||||||
|
throw new Exception("Śmieciarka nie jest w miejscu odebrania śmieci");
|
||||||
|
|
||||||
|
var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage == _typeOfGarbage);
|
||||||
|
var garbage = trashCans.Select(t => t.TakeGarbage()).Aggregate((a,b)=>a+b);
|
||||||
|
|
||||||
|
if (!_garbageCollector.TrashContainers.Any(c => c.TypeOfGarbage == _typeOfGarbage))
|
||||||
|
throw new Exception("Ta śmieciarka nie może zebrać żądanych śmieci.");
|
||||||
|
|
||||||
|
_garbageCollector.TrashContainers.FirstOrDefault(t => t.TypeOfGarbage == _typeOfGarbage).AddGarbage(garbage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.Enums;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Models.Steps
|
||||||
|
{
|
||||||
|
public class MoveStep : IStep
|
||||||
|
{
|
||||||
|
public MoveStep(Direction direction, IGarbageCollector garbageCollector)
|
||||||
|
{
|
||||||
|
this._garbageCollector = garbageCollector;
|
||||||
|
this._direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Direction _direction;
|
||||||
|
private IGarbageCollector _garbageCollector;
|
||||||
|
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
switch (_direction)
|
||||||
|
{
|
||||||
|
case Direction.Up: _garbageCollector.MoveUp(); break;
|
||||||
|
case Direction.Down: _garbageCollector.MoveDown(); break;
|
||||||
|
case Direction.Left: _garbageCollector.MoveLeft(); break;
|
||||||
|
case Direction.Right: _garbageCollector.MoveRight(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user