bool manipulate(int distance, int replacement,int start_x , int start_y, int **array,int height, int lenght)
{
if (start_y + distance > lenght && start_x + distance > height) {
returntrue;
}
cout << "coloured X: " << start_x << " and Y: " << start_y << " "<<replacement<< endl;
if (lenght > (start_y + distance)) { // West
if (array[start_x][start_y + distance] != 1) {
array[start_x][start_y + distance] = replacement;
cout << "coloured X: " << start_x << " and Y: " << start_y + distance << endl;
}
}
if (height > start_x+distance) { //North
if (array[start_x+distance][start_y] != 1) {
array[start_x+distance][start_y] = replacement;
cout << "coloured X: " << start_x + distance << " and Y: " << start_y << "value: " << array[start_x+distance][start_y]<< endl;
}
}
if (start_y-distance >= 0) { //South
if (array[start_x][start_y-distance] != 1) {
array[start_x][start_y-distance] = replacement;
cout << "coloured X: " << start_x << " and Y: " << start_y-distance<< endl;
}
}
if (start_x-distance >= 0) { //East
if (array[start_x-distance][start_y] != 1) {
array[start_x-distance][start_y] = replacement;
cout << "coloured X: " << start_x - distance << " and Y: " << start_y<< endl;
}
}
for (int x = 0; x<= distance; x++) {
if (start_x-x >= 0 && start_y+distance < lenght) {
if (array[start_x-x][start_y + distance] != 1) { // West down
array[start_x-x][start_y + distance] = replacement;
cout << "coloured X: " << start_x -x << " and Y: " << start_y+distance<< endl;
}
}
if (start_x-x >= 0 && start_y-distance >= 0) {
if (array[start_x-x][start_y - distance] != 1) { //East down
array[start_x-x][start_y - distance] = replacement;
cout << "coloured X: " << start_x -x << " and Y: " << start_y-distance<< endl;
}
}
if (start_y-x >= 0 && start_x-distance >= 0) {
if (array[start_x-distance][start_y-x] != 1) { //North <- direction
array[start_x-distance][start_y-x] = replacement;
cout << "coloured X: " << start_x -distance << " and Y: " << start_y-x<< endl;
}
}
if (start_y-x >= 0 && start_x+distance < height) {
if (array[start_x+distance][start_y-x] != 1) {
array[start_x+distance][start_y-x] = replacement; // South <- direction
cout << "coloured X: " << start_x + distance << " and Y: " << start_y-x<< endl;
}
}
if (lenght > (start_y + x) && start_x-distance >= 0) {
if (array[start_x-distance][start_y+x] != 1) { //North -> direction
array[start_x-distance][start_y+x] = replacement;
cout << "coloured X: " << start_x -distance << " and Y: " << start_y+x<< endl;
}
}
if (lenght > (start_y + x) && start_x+distance < height) {
if (array[start_x+distance][start_y+x] != 1) { //South -> direction
array[start_x+distance][start_y+x] = replacement;
cout << "coloured X: " << start_x +distance << " and Y: " << start_y+x<< endl;
}
}
if (start_x+x < height && start_y-distance >= 0) {
if (array[start_x+x][start_y - distance] != 1) { // West UP
array[start_x+x][start_y - distance] = replacement;
cout << "coloured X: " << start_x +x << " and Y: " << start_y-distance<< endl;
}
}
if (start_x+x < height && start_y+distance < lenght) {
if (array[start_x+x][start_y + distance] != 1) { // East up
array[start_x+x][start_y + distance] = replacement;
cout << "coloured X: " << start_x+x << " and Y: " << start_y+distance<< endl;
}
}
}
}
The function manipulate the elements in a certain distance from the stating point. height and length is the dimensions of the array, replacement contains the value which will be used for replacement.