Hi I'm working on a simple L-game. I want to flip an array from left to right horizontally. For example,
{ 'x',' ',' ',' ' },
{ 'x',' ',' ',' ' },
{ 'x','x',' ',' ' },
{ ' ',' ',' ',' ' }
I want to flip it to
{ ' ','x',' ',' ' },
{ ' ','x',' ',' ' },
{ 'x','x',' ',' ' },
{ ' ',' ',' ',' ' }
And this is my current code
public void flipArray() {
int rows = cells.length;
int cols = cells[0].length;
char temp[][] = new char[rows][cols];
for (int i = rows-1; i>=0; i--) {
for (int j = cols-1; j>=0; j--) {
temp[rows-1-i][cols-1-j] = cells[i][j];
}
}
for (int i=0; i<rows; i++) {
for (int j=0; j<cols; j++) {
System.out.print(temp[i][j] + " ");
}
}
}
Thank you so much any help is much appreciated. This is my desired outcome.
rand_seed = 14427 rand_seed = 14427
$ LGame.main({}) $ LGame.main({})
A i i A i i
o i o i
o i o i
o o B o o B
Move: o101 Move: o101
A i i A i i
o i | o i
o i | o i
o o B o o B
xwould be at last position of the array. So a better explanation would be aprecciated