Coverage Summary for Class: InfoUI (it.polimi.ingsw.Client.CLI)
| Class | Class, % | Method, % | Branch, % | Line, % |
|---|---|---|---|---|
| InfoUI | 0% (0/1) | 0% (0/3) | 0% (0/12) | 0% (0/24) |
1 package it.polimi.ingsw.Client.CLI; 2 3 import it.polimi.ingsw.Misc.Symbols; 4 import it.polimi.ingsw.Model.Enums.GameMode; 5 import it.polimi.ingsw.Model.Model; 6 import it.polimi.ingsw.Model.PlayerBoard; 7 import it.polimi.ingsw.Model.StudentBag; 8 import it.polimi.ingsw.Model.TurnOrder; 9 10 import java.util.List; 11 12 /** 13 * InfoUI is a graphical informative component (as a String data structure) 14 * useful to print details about the {@link TurnOrder} 15 * and the {@link StudentBag} 16 */ 17 public class InfoUI { 18 19 /** 20 * It will provide the players with a summary about the turn order, it will show the current and next players in 21 * line and highlight if you are one of them. 22 * <br> 23 * It also shows the number of remaining coins if the game is in advanced mode. 24 * 25 * @param ctx reference to the model used to access {@link Model#getMutableTurnOrder()} 26 * @param caller the player to whom the information will be displayed. It is used to highlight if you are 27 * the current or next player 28 * @return a visual description of useful information for the players: turns and coins 29 */ 30 public static String draw(Model ctx, String caller) { 31 String info = ""; 32 PlayerBoard currentPlayer = ctx.getMutableTurnOrder().getMutableCurrentPlayer(); 33 List<PlayerBoard> turnOrder = ctx.getMutableTurnOrder().getCurrentTurnOrder(); 34 35 // Prints the current player 36 if (caller.equals(currentPlayer.getNickname())) { 37 // Highlight whether the current player is the person to which the console is shown 38 info = info + currentPlayer.getNickname() + " is your turn!\n"; 39 } else 40 info = info + "It's " + currentPlayer.getNickname() + "'s turn\n"; 41 42 // Prints the next player 43 if (turnOrder.indexOf(currentPlayer) < turnOrder.size() - 1) { 44 String nextPlayer = turnOrder.get(turnOrder.indexOf(currentPlayer) + 1).getNickname(); 45 if (caller.equals(nextPlayer)) { 46 // Highlight whether the next player is the person to which the console is shown 47 info = info + "Next player: you \n"; 48 } else info = info + "Next player: " + nextPlayer + "\n"; 49 } else { 50 // This loops around the list of players to address the fact that the next player after the last one 51 // is the first one in line 52 String nextPlayer = turnOrder.get(0).getNickname(); // the first element in the list of players 53 if (caller.equals(nextPlayer)) { 54 info = info + "Next player: you \n"; 55 } else info = info + "Next player: " + nextPlayer + "\n"; 56 } 57 // Prints the coins left if the game mode is advanced 58 if (ctx.getGameMode().equals(GameMode.ADVANCED)) { 59 switch (ctx.getCoinReserve()) { 60 case 0 -> info = info + "There are no coins left"; 61 case 1 -> info = info + "There is 1 coin left"; 62 case default -> info = info + "There are " + ctx.getCoinReserve() + " coins left\n"; 63 } 64 } 65 return info; 66 } 67 68 public static String showActions() { 69 return "\tIf you are stuck, enter " + Symbols.BOLD + "`showActions` " + Symbols.RESET + Symbols.BACKGROUND; 70 } 71 }