Coverage Summary for Class: CloudUI (it.polimi.ingsw.Client.CLI)
| Class | Class, % | Method, % | Branch, % | Line, % |
|---|---|---|---|---|
| CloudUI | 0% (0/1) | 0% (0/2) | 0% (0/31) | 0% (0/56) |
1 package it.polimi.ingsw.Client.CLI; 2 3 import it.polimi.ingsw.Misc.Symbols; 4 import it.polimi.ingsw.Model.Cloud; 5 import it.polimi.ingsw.Model.Enums.PawnColour; 6 import it.polimi.ingsw.Model.Model; 7 8 /** 9 * CloudUI is a graphical representation (as a String data structure) useful to print multiple cloud components 10 * on the console. 11 * <br> 12 * The internal information of the model element is described in {@link it.polimi.ingsw.Model.Cloud}. 13 */ 14 public class CloudUI { 15 16 /** 17 * The {@link it.polimi.ingsw.Model.Cloud} will be represented with a title and its related id, 18 * and the contained students if present. 19 * According to the number of players, it will create a different layout of the clouds on the console. 20 * 21 * @param ctx is a reference to the model used to access the clouds' information. 22 * @return the representation of the clouds group. 23 */ 24 public static String draw(Model ctx) { 25 String clouds = ""; 26 switch (ctx.getClouds().size()) { 27 case 2 -> { // two clouds will be print on top of each other 28 StringBuilder twoClouds = new StringBuilder(); 29 for (Cloud c : ctx.getClouds()) { 30 StringBuilder students = new StringBuilder(); 31 32 // Prints one line for every student on the cloud, and aligns it centrally 33 for (PawnColour p : c.getContents()) { 34 students.append(Symbols.colorizeStudent(p, "\t" + Symbols.PAWN)); 35 students.append("\t\n"); 36 } 37 // Handles the empty cloud case 38 if (students.toString().equals("")) { 39 students.append("\t\t\n".repeat(3)); 40 } 41 // Appends the current cloud in the loop. 42 // Adds the current cloud title on a line. 43 // Adds the content on the cloud on separate lines. 44 twoClouds.append("\tCloud ").append(c.getId()).append("\n").append(students); 45 } 46 clouds = twoClouds.toString(); 47 } 48 49 case 3 -> { // three clouds will be print: the first pair next to each other, the third under the first 50 StringBuilder threeClouds = new StringBuilder(); 51 threeClouds.append("Cloud ").append(ctx.getClouds().get(0).getId()).append("\t\t" // divider between clouds 52 ).append("Cloud ").append(ctx.getClouds().get(1).getId()).append("\n"); // title of cloud 2 53 for (int i = 0; i < 3; i++) { // prints the content of the I and II clouds next to each other if present 54 threeClouds.append(ctx.getClouds().get(0).getContents().size() > 0 ? 55 Symbols.colorizeStudent(ctx.getClouds().get(0).getContents().get(i), "\t" + 56 Symbols.PAWN + "\t\t") : "\t\t\t"); 57 threeClouds.append(ctx.getClouds().get(1).getContents().size() > 0 ? 58 Symbols.colorizeStudent(ctx.getClouds().get(1).getContents().get(i), "\t" + 59 Symbols.PAWN) + "\n" : "\t\t\n"); 60 } 61 threeClouds.append("Cloud ").append(ctx.getClouds().get(2).getId()).append("\n"); // title of cloud 3 62 for (int i = 0; i < 3; i++) { // prints the content of the III cloud if present 63 threeClouds.append(ctx.getClouds().get(2).getContents().size() > 0 ? 64 Symbols.colorizeStudent(ctx.getClouds().get(2).getContents().get(i), "\t" 65 + Symbols.PAWN) + "\n" : 66 "\t\t\n"); 67 } 68 clouds = threeClouds.toString(); 69 } 70 71 case 4 -> { // four clouds will be print as a grid 72 StringBuilder fourClouds = new StringBuilder(); 73 fourClouds.append("Cloud ").append(ctx.getClouds().get(0).getId()).append("\t\t" // separation between clouds 74 ).append("Cloud ").append(ctx.getClouds().get(1).getId()).append("\n"); // title of cloud 2 75 for (int i = 0; i < 3; i++) { // prints the content of the I and II clouds next to each other if present 76 fourClouds.append(ctx.getClouds().get(0).getContents().size() > 0 ? 77 Symbols.colorizeStudent(ctx.getClouds().get(0).getContents().get(i), "\t" 78 + Symbols.PAWN + "\t\t") : "\t\t\t"); 79 fourClouds.append(ctx.getClouds().get(1).getContents().size() > 0 ? 80 Symbols.colorizeStudent(ctx.getClouds().get(1).getContents().get(i), "\t" 81 + Symbols.PAWN) + "\n" : "\t\t\n"); 82 } 83 fourClouds.append("Cloud ").append(ctx.getClouds().get(2).getId()).append("\t\t" // separation between clouds 84 ).append("Cloud ").append(ctx.getClouds().get(3).getId()).append("\n"); // title of cloud 4 85 for (int i = 0; i < 3; i++) { // prints the content of the III and IV clouds next to each other if present 86 fourClouds.append(ctx.getClouds().get(2).getContents().size() > 0 ? 87 Symbols.colorizeStudent(ctx.getClouds().get(2).getContents().get(i), "\t" 88 + Symbols.PAWN + "\t\t") : "\t\t\t"); 89 fourClouds.append(ctx.getClouds().get(3).getContents().size() > 0 ? 90 Symbols.colorizeStudent(ctx.getClouds().get(3).getContents().get(i), "\t" 91 + Symbols.PAWN) + "\n" : 92 "\t\t\n"); 93 } 94 clouds = fourClouds.toString(); 95 } 96 } 97 // Multiple newlines are used in conjunction with IslandUI component. 98 // If there are more islands than CloudUI component's lines we still want to print the islands stacked 99 // in GameUI. 100 return clouds + "\n\n\n"; 101 } 102 }