Commit 3422efaf authored by Haj Rezvan's avatar Haj Rezvan

Add Check for doesn't null map & visualMap elements

parent 6a106bd8
...@@ -5,6 +5,7 @@ import java.io.IOException; ...@@ -5,6 +5,7 @@ import java.io.IOException;
* @author Rezvanian 9831029 * @author Rezvanian 9831029
* @version 0.0 * @version 0.0
*/ */
public class Board implements IBoard { public class Board implements IBoard {
private final int SIZE = 9; private final int SIZE = 9;
//for programmer //for programmer
...@@ -16,6 +17,7 @@ public class Board implements IBoard { ...@@ -16,6 +17,7 @@ public class Board implements IBoard {
* This constructor, initialise the fields. * This constructor, initialise the fields.
*/ */
public Board(){ public Board(){
map = new char[81]; map = new char[81];
for (int i = 0; i < SIZE * SIZE; i++){ for (int i = 0; i < SIZE * SIZE; i++){
switch (i){ switch (i){
...@@ -71,6 +73,7 @@ public class Board implements IBoard { ...@@ -71,6 +73,7 @@ public class Board implements IBoard {
this.map[i] = '8'; this.map[i] = '8';
} }
default:{ default:{
if (this.map[i] != 'w' || this.map[i] != 'b')
this.map[i] = ' '; this.map[i] = ' ';
} }
} }
...@@ -84,6 +87,7 @@ public class Board implements IBoard { ...@@ -84,6 +87,7 @@ public class Board implements IBoard {
}else if (yColumn % 8 == 0){ }else if (yColumn % 8 == 0){
visualMap[xRow][yColumn] = '*'; visualMap[xRow][yColumn] = '*';
} else { } else {
if (this.visualMap[xRow][yColumn] != 'w' || this.visualMap[xRow][yColumn] != 'b')
visualMap[xRow][yColumn] = ' '; visualMap[xRow][yColumn] = ' ';
} }
} }
...@@ -144,7 +148,7 @@ public class Board implements IBoard { ...@@ -144,7 +148,7 @@ public class Board implements IBoard {
public void setVisualMapByPosition(int xPosition, int yPosition, char nut){ public void setVisualMapByPosition(int xPosition, int yPosition, char nut){
xPosition = 8 * (xPosition - 1) + 4; xPosition = 8 * (xPosition - 1) + 4;
yPosition = 4 * (yPosition - 1) + 2; yPosition = 4 * (yPosition - 1) + 2;
visualMap[yPosition][xPosition] = nut; this.visualMap[yPosition][xPosition] = nut;
} }
public int searchPosition(char c){ public int searchPosition(char c){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment