public bool Place(IRobot robot, IPlayingTable table, IXYCoordinates newCoordinates, MovingDirection newDirection) { if (robot == null) { throw new ArgumentNullException(nameof(robot)); } if (table == null) { throw new ArgumentNullException(nameof(table)); } if (newCoordinates == null) { throw new ArgumentNullException(nameof(newCoordinates)); } if (newDirection == MovingDirection.NOTSET) { throw new ArgumentNullException(nameof(newDirection)); } if (!table.CanMoveToCoordinates(newCoordinates)) { return(false); } table.RemoveRobot(robot); robot.CurrentCoordinates = newCoordinates; robot.CurrentFacingDirection = newDirection; return(table.AddRobot(robot)); }
public UserCommandPlace(int xCoordinate, int yCoordinate, MovingDirection direction) { var coordinatesBuilder = ServiceProvider.Instance.GetService <IXYCoordinatesBuilder>(); _newCoordinates = coordinatesBuilder.WithXYCoordinate(xCoordinate, yCoordinate).Build(); _newDirection = direction; }
public IPlayingTableBuilder WithRoot(IXYCoordinates rootCoordinates) { _rootCoordinates = rootCoordinates; return(this); }
public bool CanMoveToCoordinates(IXYCoordinates xyCoordinates) { return(!RobotsOnTable.Any(r => r.CurrentCoordinates.Equals(xyCoordinates)) && Root.X <= xyCoordinates.X && xyCoordinates.X <= Root.X + XDimensions && Root.Y <= xyCoordinates.Y && xyCoordinates.Y <= Root.Y + YDimensions); }
public bool Equals(IXYCoordinates xyCoordinates) { return(xyCoordinates.X == X && xyCoordinates.Y == Y); }