チェッカー ボード ゲームを作成する必要があり、4 つのクラスがあります。
- Cell(空のセルを表すため、toString "." を返します)
- White(白いセルを表し、toString "W" を返します)
- Black (黒のセルを表し、toString "B" を返します)
- チェッカー(ボード(Cell[8][8])をセットアップして初期化します。
文字で表される空の白と黒のセルの呼び出しに問題があり.,W,B
ます。コードでやるべきことはまだありますが、それらのメソッドを呼び出す際に助けが必要です
cell、Black、および WHite クラスは次のようになります。
public class Cell {
public static final String EMPTY=".";
int i;
int j;
String value;
public Cell(int i, int j){
this.i = i;
this.j = j;
value = EMPTY;
}
public String toString(){
return value;
}
}
Checkers クラスには、これらのメソッドがあります。他のクラスからメソッドを呼び出す方法がわからないので、Another char 配列を作成して、それらの値を入れました。
/*********initialization******/
public void init(){
board = new Cell[8][8];
char[][] a =
{
getEmptyWhite("EW"),
getEmptyWhite("WE"),
getEmptyWhite("EW"),
getEmptyWhite("EE"),
getEmptyWhite("EE"),
getEmptyWhite("BE"),
getEmptyWhite("EB"),
getEmptyWhite("BE")
};
for(int i = 0; i<8; i++){
for(int j=0; j<8; j++){
System.out.print(a[i][j]);
}
System.out.println();
}
}
public char[] getEmptyWhite(String a){
Cell empty;
Black black;
White white;
if(a.equals(empty)){
char[] emptyWhite = {'E','E','E','E','E','E','E','E'};
return emptyWhite;
}
else if(a.equals("EW")){
char[] emptyWhite = {'E','W','E','W','E','W','E','W'};
return emptyWhite;
}
else if(a.equals("EB")){
char[] emptyWhite = {'E','B','E','B','E','B','E','B'};
return emptyWhite;
} else if(a.equals("WE")){
char[] emptyWhite = {'W','E','W','E','W','E','W','E'};
return emptyWhite;
} else if(a.equals("BE")){
char[] emptyWhite = {'B','E','B','E','B','E','B','E'};
return emptyWhite;
}
return null;
}
/*********initialization ended*******/