Después de inicializar el tablero de ajedrez con Java, ¿cómo hacer que las piezas de ajedrez jueguen en el tablero de ajedrez? Sin interfaz gráfica
private.int.boardSize;
private.static.String[][].board;
public.ChessBoard(int.size) {
boardSize=size;
}
/**
*?Inicializar el tablero de ajedrez
*/
público?ChessBoard?initBoard(){
int?i;
int?j;
tablero?=?new?String[boardSize][boardSize];
for(i=0;i for(j=0;j< this .boardSize;j++){ /System.out.print("+"+"?") ; tablero[i][j] =?"" + " +"?+"+"?" ; } /System.out.println("+"); } return?this; } /** *? drop */ public?void?luoZi(int?x,int?y ) { if(tablero?! =?null?||?true){ if(x?<=?boardSize?&&?y?<=?boardSize){ int?i; int?j; for(i=0;i for(j=0;j if(j==(x-1)? &&?i?==?(y-1)){ //System.out.print("o "+"?") ; tablero[i][j]? =?" o "+"?" /p> tablero[i][j]? =?" o "+"?" ; p> }else{ /System.out .print("+"+"?") ; tablero[i][j] =?" + "+"?" > /System.out.print("+"+"?") ; tablero[i] [j]?+"+"?" ; } } /System.out.println("+"); } show(tablero); } } } } p> } } Public?void?show(String[][]?board){ ¿para?{ para?(int?j?=?0;?j? tablero[i].length;?j++)?{ System.out.print(tablero[i][ j]); } Sistema .out.println(); } } público?{ //new?ChessBoard(9).initBoard ().luoZi(5,?5); Jabalí de ajedrez d?c?=?new?ChessBoard(9); c.initBoard(); /c.show(tablero de ajedrez); c. luoZi(5,?5); } } Hice esto cuando aprendí Java por primera vez. Cambié el código por usted. Algunos lugares deben estandarizarse. Por ejemplo, debería haber un método separado para imprimir el tablero.