I'm making a project on a L_Game, now i'm stuck on the move method where my code is:
public void move(int row, int col) {
char [][] temp= new char [cells.length][];
for (int i= 0; i< cells.length; i++) {
int destRow = (i+row)%cells.length;
temp[destRow] = new char [cells[i].length];
for (int j= 0; j < cells[i].length; j++)
temp[destRow][(j+col)%cells[i].length] = cells[i][j];
}
cells= temp;
}
My move method doesn't seem to be moving the objects correctly..
So output is suppose to be like the left side, the right side is the output from my code. I know i'm obviously not moving it correctly but i don't know what i'm doing wrong either...
$ slide.move(0,2) $ slide.move(0,2)
$ slide.cells -> { $ slide.cells -> {
{ , ,o, }, | { , , , },
{ , ,o, }, | { , , ,o},
{ , ,o,o}, | { , , ,o},
{ , , , } | {o, , ,o}
} }
$ slide.move(1,2) $ slide.move(1,2)
$ slide.cells -> { $ slide.cells -> {
> { ,o,o, },
{ , , , }, { , , , },
{ , ,o, }, | { ,o, , },
{ , ,o, }, | { ,o, , }
{ , ,o,o} <
} }
- The '|' symbol identifies lines that are different.
- The '<' symbol points to lines in the left column that are not in the right column.
- The '>' symbol points to lines in the right column that are not in the left column.
Any idea on how i can fix my move method to get it to move correctly?
Thanks
.move(1,2)mean?rowandcolof what? Is it vector you want to use while moving your L shape? Or is it place you want to move some piece ofLshape? If so which piece? Is it top-left piece? You need to be more precise what you are trying to do here.