Commit 6d86460c authored by Haj Rezvan's avatar Haj Rezvan

The program updated to version 0.2

Change "map" and "visualMap" fields to "static map" and "static visualMap" fields.
Change "public Board()" constructor to "public static void initialisingBoard()" method.
Change "public void printMap()" method to "static public void printMap()" method.
parent e014cbf1
...@@ -3,78 +3,91 @@ import java.io.IOException; ...@@ -3,78 +3,91 @@ import java.io.IOException;
/** /**
* This class represents status of board and update its. * This class represents status of board and update its.
* @author Rezvanian 9831029 * @author Rezvanian 9831029
* @version 0.1 * @version 0.2
*/ */
public class Board implements IBoard { public class Board implements IBoard {
private final int SIZE = 9; private static final int SIZE = 9;
//for programmer //for programmer
private static char[] map = new char[81];
/*
Access in version 0.1
private char[] map; private char[] map;
*/
//for user //for user
private static char[][] visualMap = new char[4 * 9 + 1][8 * 9 + 1];
/*
Access in version 0.1
private char[][] visualMap; private char[][] visualMap;
*/
/** /**
* This constructor, initialise the fields. * This constructor, initialise the fields.
*/ */
public Board(){ public static void initialisingBoard(){
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){
case 0:{ case 0:{
this.map[i] = '+'; map[i] = '+';
} }
case 1:{ case 1:{
this.map[i] = 'A'; map[i] = 'A';
} }
case 2:{ case 2:{
this.map[i] = 'B'; map[i] = 'B';
} }
case 3:{ case 3:{
this.map[i] = 'C'; map[i] = 'C';
} }
case 4:{ case 4:{
this.map[i] = 'D'; map[i] = 'D';
} }
case 5:{ case 5:{
this.map[i] = 'E'; map[i] = 'E';
} }
case 6:{ case 6:{
this.map[i] = 'F'; map[i] = 'F';
} }
case 7:{ case 7:{
this.map[i] = 'G'; map[i] = 'G';
} }
case 8:{ case 8:{
this.map[i] = 'H'; map[i] = 'H';
} }
case 9:{ case 9:{
this.map[i] = '1'; map[i] = '1';
} }
case 18:{ case 18:{
this.map[i] = '2'; map[i] = '2';
} }
case 27:{ case 27:{
this.map[i] = '3'; map[i] = '3';
} }
case 36:{ case 36:{
this.map[i] = '4'; map[i] = '4';
} }
case 45:{ case 45:{
this.map[i] = '5'; map[i] = '5';
} }
case 54:{ case 54:{
this.map[i] = '6'; map[i] = '6';
} }
case 63:{ case 63:{
this.map[i] = '7'; map[i] = '7';
} }
case 72:{ case 72:{
this.map[i] = '8'; map[i] = '8';
} }
default:{ default:{
if (this.map[i] != 'w' || this.map[i] != 'b') if (map[i] != 'w' || map[i] != 'b')
this.map[i] = ' '; map[i] = ' ';
} }
} }
} }
...@@ -87,7 +100,7 @@ public class Board implements IBoard { ...@@ -87,7 +100,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') if (visualMap[xRow][yColumn] != 'w' || visualMap[xRow][yColumn] != 'b')
visualMap[xRow][yColumn] = ' '; visualMap[xRow][yColumn] = ' ';
} }
} }
...@@ -125,7 +138,7 @@ public class Board implements IBoard { ...@@ -125,7 +138,7 @@ public class Board implements IBoard {
return visualMap; return visualMap;
} }
public void printMap() throws IOException, InterruptedException{ static public void printMap() throws IOException, InterruptedException{
//clear terminal for refresh. //clear terminal for refresh.
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
...@@ -141,18 +154,18 @@ public class Board implements IBoard { ...@@ -141,18 +154,18 @@ public class Board implements IBoard {
} }
} }
//Access in version 0.0 /*Access in version 0.0
/* public void setMapByPosition(int position, char nut){ public void setMapByPosition(int position, char nut){
map[position] = nut; map[position] = nut;
} }
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;
this.visualMap[yPosition][xPosition] = nut; visualMap[yPosition][xPosition] = nut;
} }
*/ */
public int searchPosition(char c){ public int searchPosition(char c){
switch (c){ switch (c){
...@@ -186,15 +199,15 @@ public class Board implements IBoard { ...@@ -186,15 +199,15 @@ public class Board implements IBoard {
} }
} }
public void refresh() throws IOException, InterruptedException { public static void refresh() throws IOException, InterruptedException {
printMap(); printMap();
} }
public void setVisualMap(char[][] visualMap) { public void setVisualMap(char[][] map) {
this.visualMap = visualMap; visualMap = map;
} }
public void setMap(char[] map) { public void setMap(char[] map2) {
this.map = map; map = map2;
} }
} }
\ No newline at end of file
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