aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/model/Board.java
diff options
context:
space:
mode:
authorloic <git-account@loicguegan.fr>2016-09-23 09:37:06 +0200
committerloic <git-account@loicguegan.fr>2016-09-23 09:37:06 +0200
commitcb117797a68cf912b2c58d6e61b1e12025baace2 (patch)
treeabab09d1403d32747563693a854083d501d1817b /src/main/java/model/Board.java
parent8f45d6ced9e75ab382ea302050fd8fa86ea55468 (diff)
Clean codeHEADmaster
Diffstat (limited to 'src/main/java/model/Board.java')
-rw-r--r--src/main/java/model/Board.java100
1 files changed, 68 insertions, 32 deletions
diff --git a/src/main/java/model/Board.java b/src/main/java/model/Board.java
index 4d8f9b8..f40c409 100644
--- a/src/main/java/model/Board.java
+++ b/src/main/java/model/Board.java
@@ -14,12 +14,14 @@ public class Board implements IModel{
private LineAlgorithm lineAlgorithm=new LineAlgorithm();
-
public Board(int sizeX, int sizeY){
board=new int[sizeY][sizeX];
this.cleanBoard();
}
+ /**
+ * Go up
+ */
public void goUp() {
int [][] lastBoard=this.getCloneOfBoard();
@@ -37,6 +39,9 @@ public class Board implements IModel{
}
+ /**
+ * Go down
+ */
public void goDown() {
int [][] lastBoard=this.getCloneOfBoard();
@@ -49,6 +54,9 @@ public class Board implements IModel{
}
}
+ /**
+ * Go left
+ */
public void goLeft() {
int [][] lastBoard=this.getCloneOfBoard();
@@ -63,7 +71,9 @@ public class Board implements IModel{
}
}
-
+ /**
+ * Go right
+ */
public void goRight() {
int [][] lastBoard=this.getCloneOfBoard();
@@ -75,13 +85,20 @@ public class Board implements IModel{
}
}
-
+ /**
+ * Clean the board (all value to -1)
+ */
private void cleanBoard(){
for(int i=0;i<this.board.length;i++) {
this.board[i]=this.lineAlgorithm.clearLine(this.board[i]);
}
}
+ /**
+ * Get a column of the board
+ * @param index which column ?
+ * @return
+ */
private int[] getColumn(int index){
int[] column=new int[this.board.length];
for(int i=0;i<this.board.length;i++){
@@ -90,13 +107,20 @@ public class Board implements IModel{
return column;
}
+ /**
+ * Set a column of the board to a list
+ * @param column the new column value
+ * @param index
+ */
private void setColumn(int[] column, int index){
for(int i=0;i<this.board[index].length;i++){
this.board[i][index]=column[i];
}
}
-
+ /**
+ * Add a random number at a random place on the board
+ */
public void addRandomNumber(){
Collection<Integer[]> choices=new ArrayList<Integer[]>();
for(int i=0;i<this.board.length;i++) {
@@ -123,31 +147,10 @@ public class Board implements IModel{
}
}
- private boolean boardsIsEquals(int[][] board1, int[][] board2){
- if(board1.length!=board1.length){
- return false;
- }
- else {
- for (int i=0;i<board1.length;i++){
- if(!this.lineAlgorithm.linesIsEquals(board1[i],board2[i])){
- return false;
- }
- }
- }
- return true;
- }
-
- @Override
- public int[][] getBoard() {
- return this.getCloneOfBoard();
- }
-
- @Override
- public int getScore() {
- return this.lineAlgorithm.getScore();
- }
-
-
+ /**
+ * Return true if the game is loose, false else
+ * @return
+ */
public boolean isLoosed() {
int[][] copyBoard=this.getCloneOfBoard();
@@ -169,9 +172,10 @@ public class Board implements IModel{
return false;
}
-
-
-
+ /**
+ * Return a copy of the board
+ * @return
+ */
private int[][] getCloneOfBoard(){
int[][] copyBoard=new int[this.board.length][this.board[0].length];
for(int i=0;i<this.board.length;i++){
@@ -179,4 +183,36 @@ public class Board implements IModel{
}
return copyBoard;
}
+
+ /**
+ * Return true if the two board are equals
+ * @param board1
+ * @param board2
+ * @return
+ */
+ private boolean boardsIsEquals(int[][] board1, int[][] board2){
+ if(board1.length!=board1.length){
+ return false;
+ }
+ else {
+ for (int i=0;i<board1.length;i++){
+ if(!this.lineAlgorithm.linesIsEquals(board1[i],board2[i])){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public int[][] getBoard() {
+ return this.getCloneOfBoard();
+ }
+
+ @Override
+ public int getScore() {
+ return this.lineAlgorithm.getScore();
+ }
+
+
}