Coverage Summary for Class: GameUI (it.polimi.ingsw.Client.CLI)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
GameUI |
0%
(0/1)
|
0%
(0/2)
|
0%
(0/4)
|
0%
(0/13)
|
1 package it.polimi.ingsw.Client.CLI;
2
3 import it.polimi.ingsw.Misc.Symbols;
4 import it.polimi.ingsw.Model.Model;
5
6 /**
7 * GameUI is a graphical representation (as a String data structure)
8 * useful to print {@link it.polimi.ingsw.Client.CLI.CloudUI}
9 * and multiple {@link it.polimi.ingsw.Client.CLI.IslandUI} components
10 * next to each other on the console.
11 */
12 public class GameUI {
13
14 /**
15 * The console will be populated with all the island groups in the island field followed by the clouds on
16 * the same multiline block.
17 *
18 * @param ctx is a reference to the model used to access the {@link it.polimi.ingsw.Model.IslandField} to print
19 * the {@link it.polimi.ingsw.Client.CLI.IslandUI} and passed to the
20 * {@link it.polimi.ingsw.Client.CLI.CloudUI}
21 * @return a composed view of islands and clouds
22 */
23 public static String draw(Model ctx) {
24 // The background colour helpful to enhance contrast between black towers and the default black background console
25 StringBuilder screen = new StringBuilder(Symbols.BACKGROUND);
26
27 String clouds = CloudUI.draw(ctx); // draws the cloud component which will be stripped and printed line by line
28 int groupsSize = ctx.getMutableIslandField().getMutableGroups().size();
29 // The number of rows of the UI component depends on the number of island groups.
30 // If there are less island groups than the number of CloudUI's lines, padding should be added in the form of
31 // empty rows to replace the IslandUI component.
32 // The constant '8' is the minimum number of lines/IslandUIs needed to correctly display the cloud component.
33 int rows = Math.max(groupsSize, 8);
34 for (int i = 0; i < rows; i++) { // on each row will be printed an IslandUI and one line of CloudUI
35 // on every line prints the island group but if there are none to print, it fills the space with
36 // an empty line
37 if (i < ctx.getMutableIslandField().getMutableGroups().size()) {
38 String currentIsland = IslandUI.draw(ctx.getMutableIslandField().getMutableGroups().get(i), ctx);
39 screen.append(currentIsland).append("\t".repeat(2)); // '\t' is used for horizontal separation between islands and clouds
40 } else screen.append(IslandUI.drawEmptyRow(ctx)).append("\t".repeat(2));
41
42 // This will print just one line of the clouds UI component
43 screen.append(clouds, 0, clouds.indexOf('\n') + 1);
44 clouds = clouds.substring(clouds.indexOf('\n') + 1);
45 }
46
47 return screen.toString();
48 }
49 }