50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Enums;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Exceptions;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector;
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
|
|
|
|
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
|
|
{
|
|
public class SpillStep : IStep
|
|
{
|
|
public SpillStep(GarbageType typeOfGarbage)
|
|
{
|
|
this._typeOfGarbage = typeOfGarbage;
|
|
}
|
|
|
|
private GarbageType _typeOfGarbage;
|
|
|
|
public void Invoke(IGarbageCollector _garbageCollector, object [,] grid)
|
|
{
|
|
var _dump = (ADump)grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y];
|
|
if(_garbageCollector.Coords != _dump.Coords)
|
|
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
|
|
|
|
if(_dump.TypeOfGarbage.GarbageType != _typeOfGarbage)
|
|
throw new TrashContainerNotFound($"Wysypisko nie przyjmuje smieci typu {_typeOfGarbage}");
|
|
|
|
if(_garbageCollector.TrashContainers.All(c => c.TypeOfGarbage.GarbageType != _typeOfGarbage))
|
|
throw new TrashContainerNotFound($"Smieciarka nie ma pojemnika na {_typeOfGarbage}!");
|
|
|
|
var garbage = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage)
|
|
.Select(t => t.TakeGarbage())
|
|
.Aggregate((a, b) => a + b);
|
|
|
|
_dump.AddGarbage(garbage);
|
|
for (int x = 0; x < grid.GetLength(0); x++)
|
|
{
|
|
for (int y = 0; y < grid.GetLength(1); y++)
|
|
{
|
|
if (grid[x, y] is Road2) grid[x, y] = new Road1(new Coords(x, y));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|