0
How can I switch values between arrays?
I need to change the order to 0-15. Im having trouble on how to switch the values. help :,v https://code.sololearn.com/cMVSDd0kD4PR/?ref=app
2 odpowiedzi
0
Hi,
like this?
public class change {
private int [][]tab;
public change(){
int [][]numeracion = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
tab=numeracion;
}
public void showtab(){
for(int i=0;i<4;i++){
for(int j= 0;j<4;j++){
System.out.print(tab[i][j]+" ");
}
System.out.println();
}
System.out.println();
}
public void goback(){
int courant;
for(int i=3;i>=0;i--){
for(int j=2;j>=0;j--){
courant=tab[i][j];
tab[i][j]=tab[i][j+1];
tab[i][j+1]=courant;
}
if(i!=0){
courant=tab[i-1][3];
tab[i-1][3]=tab[i][0];
tab[i][0]=courant;
}
}
}
public static void main(String [] args){
change c = new change();
c.showtab();
c.goback();
c.showtab();
}
}
0
yes but not exactly. Its suppose to be a sliding puzzle game.
0 being the empty spot and it doesnt necessary need to be the last spot.
so lets say 0 is at array [1][2] for example. I should only allow the options to move from array [1][1], [1][3],
[0][2] and [2][2], if im right.