I managed to move it up, left and right but when i try to move it down it goes to the last Y position in the array instead of the Y position below it.
the code i wrote to move it up, left and to the right works!
the name of the array is "mapa[h][b]", the "help" variable has the same value as the values i want to move but as an int instead of a char, the variable "i" is for the Y position and the variable "j" is for the X position
//movement upwards
for (i=0;i<h;i++){
for (j=0;j<b;j++){
if(mapa[i][j]==help){
aux=mapa[i-1][j];
mapa[i-1][j]=mapa[i][j];
mapa[i][j]=aux;
break;
break;
}
}
}
//movement to the left
for (i=0;i<h;i++){
for (j=0;j<b;j++){
if(mapa[i][j]==help){
aux=mapa[i][j-1];
mapa[i][j-1]=mapa[i][j];
mapa[i][j]=aux;
break;
break;
}
}
}
//movement to the right
for (i=0;i<h;i++){
for (j=0;j<b;j++){
if(mapa[i][j]==help){
aux=mapa[i][j+1];
mapa[i][j+1]=mapa[i][j];
mapa[i][j]=aux;
break;
break;
}
}
}
And as I said before, this part works, what I did its just to exchange the value I want to move with the one on the position I want to move it to, to locate the value I want to move I use the for() cycles to "scan" the array and the if() is meant to find it, when the if() finds the wanted value I add one to the Y or X position, but when i try to move it down using the same logic
for (i=0;i<h;i++){
for (j=0;j<b;j++){
if(mapa[i][j]==help){
aux=mapa[i+1][j];
mapa[i+1][j]=mapa[i][j];
mapa[i][j]=aux;
break;
break;
}
}
}
it just moves to the bottom of the array regardles of its current location on the Y position