Advertisement
akwatic97460

Untitled

Mar 29th, 2020
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. public class View implements InterfaceView {
  2.  
  3. public void displayBoard(Board board, Animal... animals) {
  4.  
  5. String[][] plateau = new String[board.getNbrow()][board.getNbcolumn()];
  6.  
  7. for (int i = 0; i < plateau.length; i++) {
  8.  
  9. for (int j = 0; j < plateau[0].length; j++) {
  10.  
  11. Position position = new Position(i, j);
  12.  
  13. if (null == board.getSquare(position)) {
  14.  
  15. plateau[i][j] = TerminalColor.BG_WHITE
  16. //+ " NULL "+
  17. + " "
  18. + TerminalColor.DEFAULT;
  19.  
  20. } else {
  21.  
  22. switch (board.getSquareType(position)) {
  23.  
  24. case STAR:
  25. plateau[i][j] = TerminalColor.BG_RED_FG_WHITE
  26. //+ " STAR "
  27. + "| * |"
  28. + TerminalColor.DEFAULT;
  29.  
  30. break;
  31.  
  32. case GRASS:
  33. plateau[i][j] = TerminalColor.BG_GREEN_FG_WHITE
  34. //+ " GRASS "
  35. + "| |"
  36. + TerminalColor.DEFAULT;
  37. break;
  38.  
  39. default:
  40. plateau[i][j] = TerminalColor.BG_BLUE
  41. //+ " NULL "+
  42. + " "
  43. + TerminalColor.DEFAULT;
  44.  
  45. break;
  46.  
  47. }
  48.  
  49. }
  50.  
  51. for (Animal pet : animals) {
  52.  
  53. if (position.equals(pet.getPositionOnBoard())) {
  54.  
  55. if (pet.getClass().getSimpleName().toString().equals("Spider")) {
  56.  
  57. plateau[i][j] = TerminalColor.BG_GREEN_FG_WHITE // fg black
  58. + "m°°m"
  59. + TerminalColor.DEFAULT;
  60.  
  61. } else if (pet.getClass().getSimpleName().toString().equals("Snail")) {
  62.  
  63. plateau[i][j] = TerminalColor.RED
  64. + " Q "
  65. + TerminalColor.DEFAULT;
  66.  
  67. }
  68.  
  69. }
  70.  
  71. }
  72.  
  73. }
  74.  
  75. System.out.println();
  76.  
  77. }
  78.  
  79. for (int x = 0; x < plateau.length; x++) {
  80.  
  81. for (int y = 0; y < plateau[0].length; y++)
  82. System.out.print(plateau[x][y]);
  83.  
  84. System.out.println();
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement