Coverage Summary for Class: IslandUI (it.polimi.ingsw.Client.CLI)
Class |
Method, %
|
Branch, %
|
Line, %
|
IslandUI |
0%
(0/3)
|
0%
(0/17)
|
0%
(0/37)
|
IslandUI$1 |
0%
(0/1)
|
0%
(0/1)
|
Total |
0%
(0/4)
|
0%
(0/17)
|
0%
(0/38)
|
1 package it.polimi.ingsw.Client.CLI;
2
3 import it.polimi.ingsw.Misc.Symbols;
4 import it.polimi.ingsw.Misc.Utils;
5 import it.polimi.ingsw.Model.Enums.PawnColour;
6 import it.polimi.ingsw.Model.IslandGroup;
7 import it.polimi.ingsw.Model.Model;
8
9 import java.util.List;
10
11 /**
12 * IslandUI allows to print a placeholder containing an {@link IslandGroup} representation or an empty row
13 * which could be needed if there was previously an IslandGroup on the console which does not exist anymore
14 * in the model
15 */
16 public class IslandUI {
17
18 /**
19 * The {@link IslandGroup} will be represented with its ID value and the students and towers on it.
20 * <br>
21 * The students will be ordered by frequency on the island to better highlight the influence.
22 * <br>
23 * Mother Nature is represented by an asterisk
24 * <br>
25 * The number of tower is shown via a number
26 *
27 * @param i the subject to be represented
28 * @param ctx reference to the model used to identify the presence of the mother nature piece on the island group
29 * @return the representation of an island group.
30 */
31 public static String draw(IslandGroup i, Model ctx) {
32 // Adds an identifier if the island contains MotherNature
33 String mn = ctx.getMutableIslandField().getMutableMotherNaturePosition().equals(i) ? "*" : "";
34
35 StringBuilder students = new StringBuilder();
36 // Prints each student on the island
37 List<PawnColour> sortedStudents = Utils.sortByFrequency(i.getStudents());
38 for (PawnColour p : sortedStudents) {
39 students.append(Symbols.colorizeStudent(p, Symbols.PAWN + " "));
40 }
41
42 // Adds padding if the current island doesn't hold the most students
43 int maxStudents = 0;
44 for (IslandGroup ig : ctx.getMutableIslandField().getMutableGroups()) {
45 maxStudents = Math.max(maxStudents, ig.getStudents().size());
46 }
47 if (i.getStudents().size() < maxStudents) {
48 students.append(" ".repeat(maxStudents - i.getStudents().size())); // padding
49 }
50
51 // Prints the tower representation accounting for team and quantity
52 String tower = "";
53 if (i.getTowerColour().isPresent()) {
54 switch (i.getTowerColour().get()) {
55 case BLACK -> tower = tower + "\t" + Symbols.colour(Symbols.TOWER + " ", Symbols.BLACK)
56 + i.getTowerCount();
57 case GRAY -> tower = tower + "\t" + Symbols.colour(Symbols.TOWER + " ", Symbols.GRAY)
58 + i.getTowerCount();
59 case WHITE -> tower = tower + "\t" + Symbols.colour(Symbols.TOWER + " ", Symbols.WHITE)
60 + i.getTowerCount();
61
62 }
63 } else tower = "\t" + " ".repeat(4);
64
65 String islandTitle = "Island " + i.getId(); // island's title and id
66 if (i.getMutableNoEntryTiles().size() > 0) {
67 // The title will be crossed out if the island's influence cannot be changed
68 islandTitle = Symbols.OVERLAY + islandTitle + Symbols.RESET + Symbols.BACKGROUND;
69 }
70 return mn + islandTitle + ":\t" + students + tower;
71 }
72
73 /**
74 * It basically provides the same result as {@link IslandUI#draw(IslandGroup, Model)} but it replaces
75 * all characters with whitespaces (except tabulations)
76 *
77 * @param ctx reference to the model used to identify the island group containing the most students
78 * @return an all whitespace's filled String, long enough to fill the IslandUIs' composition
79 */
80 public static String drawEmptyRow(Model ctx) {
81 String mn = "";
82
83 String islandTitle = " ".repeat(10);
84
85 String students = "";
86
87 int maxStudents = 0;
88 for (IslandGroup ig : ctx.getMutableIslandField().getMutableGroups()) {
89 maxStudents = Math.max(maxStudents, ig.getStudents().size());
90 }
91 students = students + " ".repeat(maxStudents);
92
93 String tower = "\t" + " ".repeat(4);
94
95 return mn + islandTitle + " \t" + students + tower;
96 }
97 }
98
99