Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- void printMap() {
- GameMap map = gs.getMap();
- List<Box> boxes = map.getBoxes();
- final String ANSI_BLACK = "\u001B[30m";
- final String ANSI_RED = "\u001B[31m";
- final String ANSI_GREEN = "\u001B[32m";
- final String ANSI_YELLOW = "\u001B[33m";
- final String ANSI_BLUE = "\u001B[34m";
- final String ANSI_PURPLE = "\u001B[35m";
- final String ANSI_WHITE = "\u001B[37m";
- final int ROOM_HEIGHT = 5;
- StringBuilder printer = new StringBuilder();
- String toPrint;
- boolean done = false;
- boolean row_complete = false;
- int x = 0;
- int y = 2;
- Box b = map.getBoxByCoordinates(new Coordinates(x ,y)).orElseThrow();
- boolean zerozero = false;
- Optional<Box> topRoom, leftRoom, rightRoom, bottomRoom;
- boolean topExists, leftExists, rightExists, bottomExists;
- while(!done) {
- for(int curr_row=0; curr_row<ROOM_HEIGHT; curr_row++) {
- row_complete = false;
- while (!row_complete) {
- topRoom = map.getBorderByDirection(b, CardinalEnum.TOP);
- topExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX(), b.getCoordinates().getY()+1)).isPresent();
- leftRoom = map.getBorderByDirection(b, CardinalEnum.LEFT);
- leftExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX()-1, b.getCoordinates().getY())).isPresent();
- rightRoom = map.getBorderByDirection(b, CardinalEnum.RIGHT);
- rightExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX()+1, b.getCoordinates().getY())).isPresent();
- bottomRoom = map.getBorderByDirection(b, CardinalEnum.BOTTOM);
- bottomExists = map.getBoxByCoordinates(new Coordinates(b.getCoordinates().getX(), b.getCoordinates().getY()-1)).isPresent();
- if(zerozero)
- printer.append(" ");
- else {
- switch (b.getRoom()) {
- case "WHITE":
- printer.append(ANSI_WHITE);
- break;
- case "YELLOW":
- printer.append(ANSI_YELLOW);
- break;
- case "PURPLE":
- printer.append(ANSI_PURPLE);
- break;
- case "RED":
- printer.append(ANSI_RED);
- break;
- case "BLUE":
- printer.append(ANSI_BLUE);
- break;
- case "GREEN":
- printer.append(ANSI_GREEN);
- break;
- default:
- printer.append(ANSI_BLACK);
- break;
- }
- if (curr_row == 0) {
- if (!leftExists && !topExists)
- printer.append("╔");
- if (!leftExists && topExists)
- printer.append("╠");
- if (leftExists)
- printer.append("╦");
- if (topExists && topRoom.isPresent()) {
- if (b.getBorder().get(CardinalEnum.TOP).getTraversable()) {
- if (topRoom.get().isSameRoom(b))
- printer.append(" ");
- else
- printer.append("═ ═");
- } else
- printer.append("═════");
- } else
- printer.append("═════");
- if (!rightExists && !topExists)
- printer.append("╗");
- if (!rightExists && topExists)
- printer.append("╣");
- if (rightExists)
- printer.append("╦");
- }
- if (curr_row > 0 && curr_row < ROOM_HEIGHT - 1) {
- if (!leftExists)
- printer.append("║");
- else {
- if (leftRoom.isPresent()) {
- if (leftRoom.get().isSameRoom(b))
- printer.append(":");
- else {
- if (b.getBorder().get(CardinalEnum.LEFT).getTraversable()) {
- /*if (curr_row == 1 || curr_row == ROOM_HEIGHT - 2)
- printer.append("║");
- else*/
- printer.append(" ");
- } else {
- printer.append("║");
- }
- }
- }
- }
- printer.append(" ");
- if (!rightExists)
- printer.append("║");
- else {
- if (rightRoom.isPresent()) {
- if (rightRoom.get().isSameRoom(b))
- printer.append(":");
- else {
- if (b.getBorder().get(CardinalEnum.RIGHT).getTraversable()) {
- /*if (curr_row == 1 || curr_row == ROOM_HEIGHT - 2)
- printer.append("║");
- else*/
- printer.append(" ");
- } else {
- printer.append("║");
- }
- }
- }
- }
- }
- if (curr_row == ROOM_HEIGHT - 1) {
- if (leftRoom.isEmpty() && bottomRoom.isEmpty())
- printer.append("╚");
- if (leftRoom.isEmpty() && bottomRoom.isPresent())
- printer.append("╠");
- if (leftRoom.isPresent())
- printer.append("╩");
- if (bottomExists && bottomRoom.isPresent()) {
- if (b.getBorder().get(CardinalEnum.BOTTOM).getTraversable()) {
- if (bottomRoom.get().isSameRoom(b))
- printer.append(" ");
- else
- printer.append("═ ═");
- } else
- printer.append("═════");
- } else
- printer.append("═════");
- if (!rightExists && !bottomExists)
- printer.append("╝");
- if (!rightExists && bottomExists)
- printer.append("╣");
- if (rightExists)
- printer.append("╩");
- }
- printer.append("\u001B[39;49m");
- }
- x++;
- zerozero = false;
- if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
- b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
- else {
- x = 0;
- if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
- b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
- else
- zerozero = (y==0);
- printer.append("\n");
- row_complete = true;
- }
- }
- }
- y--;
- if (map.getBoxByCoordinates(new Coordinates(x, y)).isPresent())
- b = map.getBoxByCoordinates(new Coordinates(x, y)).get();
- else {
- if(y==0)
- zerozero = true;
- else
- done = true;
- }
- }
- toPrint = printer.toString();
- System.out.println(toPrint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement