Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String toString()
- {
- StringBuilder tostring = new StringBuilder();
- int k = 0;
- for (int j=7;j>=0;j--)
- {
- for (int i=0;i<8;i++)
- {
- if (tablero[i][j]!=null)
- {
- if (k > 0)
- {
- tostring.append("t");
- k = 0;
- }
- if (tablero[i][j].getTipo()==Tipo.TORRE && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("T");}
- else if (tablero[i][j].getTipo()==Tipo.TORRE && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("t");}
- else if (tablero[i][j].getTipo()==Tipo.CABALLO && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("C");}
- else if (tablero[i][j].getTipo()==Tipo.CABALLO && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("c");}
- else if (tablero[i][j].getTipo()==Tipo.ALFIL && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("A");}
- else if (tablero[i][j].getTipo()==Tipo.ALFIL && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("a");}
- else if (tablero[i][j].getTipo()==Tipo.DAMA && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("D");}
- else if (tablero[i][j].getTipo()==Tipo.DAMA && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("d");}
- else if (tablero[i][j].getTipo()==Tipo.REY && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("R");}
- else if (tablero[i][j].getTipo()==Tipo.REY && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("r");}
- else if (tablero[i][j].getTipo()==Tipo.PEON && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("P");}
- else if (tablero[i][j].getTipo()==Tipo.PEON && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("p");}
- }
- else
- k += k; //añadimos 1 en las casillas nulas
- }
- if (k > 0)
- {
- tostring.append("t");
- k = 0;
- }
- tostring.append("/");
- }
- return tostring.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment