tuamigo

Untitled

Oct 26th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public String toString()
  2. {
  3. StringBuilder tostring = new StringBuilder();
  4. int k = 0;
  5.  
  6. for (int j=7;j>=0;j--)
  7. {
  8. for (int i=0;i<8;i++)
  9. {
  10. if (tablero[i][j]!=null)
  11. {
  12. if (k > 0)
  13. {
  14. tostring.append("t");
  15. k = 0;
  16. }
  17.  
  18. if (tablero[i][j].getTipo()==Tipo.TORRE && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("T");}
  19. else if (tablero[i][j].getTipo()==Tipo.TORRE && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("t");}
  20. else if (tablero[i][j].getTipo()==Tipo.CABALLO && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("C");}
  21. else if (tablero[i][j].getTipo()==Tipo.CABALLO && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("c");}
  22. else if (tablero[i][j].getTipo()==Tipo.ALFIL && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("A");}
  23. else if (tablero[i][j].getTipo()==Tipo.ALFIL && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("a");}
  24. else if (tablero[i][j].getTipo()==Tipo.DAMA && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("D");}
  25. else if (tablero[i][j].getTipo()==Tipo.DAMA && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("d");}
  26. else if (tablero[i][j].getTipo()==Tipo.REY && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("R");}
  27. else if (tablero[i][j].getTipo()==Tipo.REY && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("r");}
  28. else if (tablero[i][j].getTipo()==Tipo.PEON && tablero[i][j].getColor()==Color.BLANCO) {tostring.append("P");}
  29. else if (tablero[i][j].getTipo()==Tipo.PEON && tablero[i][j].getColor()==Color.NEGRO) {tostring.append("p");}
  30. }
  31. else
  32. k += k; //añadimos 1 en las casillas nulas
  33. }
  34. if (k > 0)
  35. {
  36. tostring.append("t");
  37. k = 0;
  38. }
  39. tostring.append("/");
  40. }
  41.  
  42. return tostring.toString();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment