Add 2 and 4

This commit is contained in:
loic 2016-09-22 20:57:53 +02:00
parent 641043d526
commit 93953a52ce
2 changed files with 20 additions and 4 deletions

View file

@ -24,28 +24,24 @@ public class ModelAdapter implements IModelAdapter, IObservable{
@Override
public void goUp() {
model.goUp();
model.addRandomNumber();
this.notifyObservers();
}
@Override
public void goDown() {
model.goDown();
model.addRandomNumber();
this.notifyObservers();
}
@Override
public void goLeft() {
model.goLeft();
model.addRandomNumber();
this.notifyObservers();
}
@Override
public void goRight() {
model.goRight();
model.addRandomNumber();
this.notifyObservers();
}

View file

@ -20,6 +20,8 @@ public class Board implements IModel{
}
public void goUp() {
int [][] lastBoard=this.getCloneOfBoard();
for(int i=0;i<this.board[0].length;i++){
int[] column=this.lineAlgorithm.reverseLine(this.getColumn(i));
@ -28,30 +30,48 @@ public class Board implements IModel{
this.setColumn(this.lineAlgorithm.reverseLine(this.lineAlgorithm.mergeRight(column)), i);
}
if(!boardsIsEquals(this.board,lastBoard)){
this.addRandomNumber();
}
}
public void goDown() {
int [][] lastBoard=this.getCloneOfBoard();
for(int i=0;i<this.board[0].length;i++){
int[] column=this.getColumn(i);
this.setColumn(this.lineAlgorithm.mergeRight(column), i);
}
if(!boardsIsEquals(this.board,lastBoard)){
this.addRandomNumber();
}
}
public void goLeft() {
int [][] lastBoard=this.getCloneOfBoard();
for(int i=0;i<this.board.length;i++){
int[] tmp=this.lineAlgorithm.reverseLine(board[i]);
tmp=this.lineAlgorithm.mergeRight(tmp);
tmp=this.lineAlgorithm.reverseLine(tmp);
this.board[i]=tmp;
}
if(!boardsIsEquals(this.board,lastBoard)){
this.addRandomNumber();
}
}
public void goRight() {
int [][] lastBoard=this.getCloneOfBoard();
for(int i=0;i<this.board.length;i++){
this.board[i]=this.lineAlgorithm.mergeRight(board[i]);
}
if(!boardsIsEquals(this.board,lastBoard)){
this.addRandomNumber();
}
}