2019-03-13 15:31:33 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-04-22 09:24:16 +02:00
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Enums;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
|
2019-03-13 15:31:33 +01:00
|
|
|
|
|
2019-04-22 09:24:16 +02:00
|
|
|
|
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
|
2019-03-13 15:31:33 +01:00
|
|
|
|
{
|
|
|
|
|
public class MoveStep : IStep
|
|
|
|
|
{
|
2019-04-22 03:16:30 +02:00
|
|
|
|
public MoveStep(Direction direction)
|
2019-03-13 15:31:33 +01:00
|
|
|
|
{
|
|
|
|
|
this._direction = direction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Direction _direction;
|
|
|
|
|
private IGarbageCollector _garbageCollector;
|
|
|
|
|
|
2019-05-05 17:54:12 +02:00
|
|
|
|
public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid)
|
2019-03-13 15:31:33 +01:00
|
|
|
|
{
|
2019-04-22 09:24:16 +02:00
|
|
|
|
if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1)
|
2019-04-22 14:55:47 +02:00
|
|
|
|
grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] = new Road2(new Coords(_garbageCollector.Coords.X, _garbageCollector.Coords.Y));
|
2019-04-23 11:24:07 +02:00
|
|
|
|
var pass = false;
|
2019-03-13 15:31:33 +01:00
|
|
|
|
switch (_direction)
|
|
|
|
|
{
|
2019-04-23 11:24:07 +02:00
|
|
|
|
case Direction.Up:
|
2019-05-05 17:54:12 +02:00
|
|
|
|
pass = _garbageCollector.MoveUp();
|
2019-04-23 11:24:07 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Direction.Down:
|
2019-05-05 17:54:12 +02:00
|
|
|
|
pass = _garbageCollector.MoveDown();
|
2019-04-23 11:24:07 +02:00
|
|
|
|
break;
|
|
|
|
|
case Direction.Left:
|
2019-05-05 17:54:12 +02:00
|
|
|
|
pass = _garbageCollector.MoveLeft();
|
2019-04-23 11:24:07 +02:00
|
|
|
|
break;
|
|
|
|
|
case Direction.Right:
|
2019-05-05 17:54:12 +02:00
|
|
|
|
pass = _garbageCollector.MoveRight();
|
2019-04-23 11:24:07 +02:00
|
|
|
|
break;
|
2019-03-13 15:31:33 +01:00
|
|
|
|
}
|
2019-04-23 11:24:07 +02:00
|
|
|
|
if (pass)
|
|
|
|
|
{
|
|
|
|
|
_garbageCollector.Counter++;
|
|
|
|
|
}
|
|
|
|
|
return pass;
|
2019-03-13 15:31:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|