Advertisement
Guest User

Untitled

a guest
May 19th, 2019
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.19 KB | None | 0 0
  1.     @Test
  2.     void printMap() {
  3.         GameMap map = gs.getMap();
  4.         List<Box> boxes = map.getBoxes();
  5.         final String ANSI_BLACK = "\u001B[30m";
  6.         final String ANSI_RED = "\u001B[31m";
  7.         final String ANSI_GREEN = "\u001B[32m";
  8.         final String ANSI_YELLOW = "\u001B[33m";
  9.         final String ANSI_BLUE = "\u001B[34m";
  10.         final String ANSI_PURPLE = "\u001B[35m";
  11.         final String ANSI_WHITE = "\u001B[37m";
  12.         final int ROOM_HEIGHT = 5;
  13.  
  14.         StringBuilder printer = new StringBuilder();
  15.         String toPrint;
  16.         boolean done = false;
  17.         boolean row_complete = false;
  18.         int x = 0;
  19.         int y = 2;
  20.         Box b = map.getBoxByCoordinates(new Coordinates(x ,y)).orElseThrow();
  21.         boolean zerozero = false;
  22.         Optional<Box> topRoom, leftRoom, rightRoom, bottomRoom;
  23.         boolean topExists, leftExists, rightExists, bottomExists;
  24.  
  25.         while(!done) {
  26.  
  27.             for(int curr_row=0; curr_row<ROOM_HEIGHT; curr_row++) {
  28.                 row_complete = false;
  29.                 while (!row_complete) {
  30.  
  31.                     topRoom = map.getBorderByDirection(b, CardinalEnum.TOP);
  32.                     topExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX(), b.getCoordinates().getY()+1)).isPresent();
  33.                     leftRoom = map.getBorderByDirection(b, CardinalEnum.LEFT);
  34.                     leftExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX()-1, b.getCoordinates().getY())).isPresent();
  35.                     rightRoom = map.getBorderByDirection(b, CardinalEnum.RIGHT);
  36.                     rightExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX()+1, b.getCoordinates().getY())).isPresent();
  37.                     bottomRoom = map.getBorderByDirection(b, CardinalEnum.BOTTOM);
  38.                     bottomExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX(), b.getCoordinates().getY()-1)).isPresent();
  39.  
  40.                     if(zerozero)
  41.                         printer.append("       ");
  42.                     else {
  43.                         switch (b.getRoom()) {
  44.                             case "WHITE":
  45.                                 printer.append(ANSI_WHITE);
  46.                                 break;
  47.                             case "YELLOW":
  48.                                 printer.append(ANSI_YELLOW);
  49.                                 break;
  50.                             case "PURPLE":
  51.                                 printer.append(ANSI_PURPLE);
  52.                                 break;
  53.                             case "RED":
  54.                                 printer.append(ANSI_RED);
  55.                                 break;
  56.                             case "BLUE":
  57.                                 printer.append(ANSI_BLUE);
  58.                                 break;
  59.                             case "GREEN":
  60.                                 printer.append(ANSI_GREEN);
  61.                                 break;
  62.                             default:
  63.                                 printer.append(ANSI_BLACK);
  64.                                 break;
  65.                         }
  66.  
  67.                         if (curr_row == 0) {
  68.                             if (!leftExists && !topExists)
  69.                                 printer.append("╔");
  70.                             if (!leftExists && topExists)
  71.                                 printer.append("╠");
  72.                             if (leftExists)
  73.                                 printer.append("╦");
  74.  
  75.                             if (topExists && topRoom.isPresent()) {
  76.                                 if (b.getBorder().get(CardinalEnum.TOP).getTraversable()) {
  77.                                     if (topRoom.get().isSameRoom(b))
  78.                                         printer.append("     ");
  79.                                     else
  80.                                         printer.append("═   ═");
  81.                                 } else
  82.                                     printer.append("═════");
  83.                             } else
  84.                                 printer.append("═════");
  85.  
  86.                             if (!rightExists && !topExists)
  87.                                 printer.append("╗");
  88.                             if (!rightExists && topExists)
  89.                                 printer.append("╣");
  90.                             if (rightExists)
  91.                                 printer.append("╦");
  92.                         }
  93.  
  94.                         if (curr_row > 0 && curr_row < ROOM_HEIGHT - 1) {
  95.                             if (!leftExists)
  96.                                 printer.append("║");
  97.                             else {
  98.                                 if (leftRoom.isPresent()) {
  99.                                     if (leftRoom.get().isSameRoom(b))
  100.                                         printer.append(":");
  101.                                     else {
  102.                                         if (b.getBorder().get(CardinalEnum.LEFT).getTraversable()) {
  103.                                     /*if (curr_row == 1 || curr_row == ROOM_HEIGHT - 2)
  104.                                         printer.append("║");
  105.                                     else*/
  106.                                             printer.append(" ");
  107.                                         } else {
  108.                                             printer.append("║");
  109.                                         }
  110.                                     }
  111.                                 }
  112.                             }
  113.  
  114.                             printer.append("     ");
  115.  
  116.                             if (!rightExists)
  117.                                 printer.append("║");
  118.                             else {
  119.                                 if (rightRoom.isPresent()) {
  120.                                     if (rightRoom.get().isSameRoom(b))
  121.                                         printer.append(":");
  122.                                     else {
  123.                                         if (b.getBorder().get(CardinalEnum.RIGHT).getTraversable()) {
  124.                                     /*if (curr_row == 1 || curr_row == ROOM_HEIGHT - 2)
  125.                                         printer.append("║");
  126.                                     else*/
  127.                                             printer.append(" ");
  128.                                         } else {
  129.                                             printer.append("║");
  130.                                         }
  131.                                     }
  132.                                 }
  133.                             }
  134.                         }
  135.  
  136.                         if (curr_row == ROOM_HEIGHT - 1) {
  137.                             if (leftRoom.isEmpty() && bottomRoom.isEmpty())
  138.                                 printer.append("╚");
  139.                             if (leftRoom.isEmpty() && bottomRoom.isPresent())
  140.                                 printer.append("╠");
  141.                             if (leftRoom.isPresent())
  142.                                 printer.append("╩");
  143.  
  144.                             if (bottomExists && bottomRoom.isPresent()) {
  145.                                 if (b.getBorder().get(CardinalEnum.BOTTOM).getTraversable()) {
  146.                                     if (bottomRoom.get().isSameRoom(b))
  147.                                         printer.append("     ");
  148.                                     else
  149.                                         printer.append("═   ═");
  150.                                 } else
  151.                                     printer.append("═════");
  152.                             } else
  153.                                 printer.append("═════");
  154.  
  155.                             if (!rightExists && !bottomExists)
  156.                                 printer.append("╝");
  157.                             if (!rightExists && bottomExists)
  158.                                 printer.append("╣");
  159.                             if (rightExists)
  160.                                 printer.append("╩");
  161.                         }
  162.  
  163.                         printer.append("\u001B[39;49m");
  164.                     }
  165.  
  166.                     x++;
  167.                     zerozero = false;
  168.  
  169.                     if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
  170.                         b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
  171.                     else {
  172.                         x = 0;
  173.                         if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
  174.                             b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
  175.                         else
  176.                             zerozero = (y==0);
  177.                         printer.append("\n");
  178.                         row_complete = true;
  179.                     }
  180.                 }
  181.             }
  182.             y--;
  183.             if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
  184.                 b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
  185.             else {
  186.                 if(y==0)
  187.                     zerozero = true;
  188.                 else
  189.                     done = true;
  190.             }
  191.         }
  192.         toPrint = printer.toString();
  193.         System.out.println(toPrint);
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement