Coverage Summary for Class: ClientView (it.polimi.ingsw.Client.CLI)

Class Class, % Method, % Branch, % Line, %
ClientView 0% (0/1) 0% (0/23) 0% (0/16) 0% (0/62)


1 package it.polimi.ingsw.Client.CLI; 2  3 import it.polimi.ingsw.Misc.Symbols; 4 import it.polimi.ingsw.Model.*; 5 import it.polimi.ingsw.Model.Enums.GameMode; 6 import it.polimi.ingsw.Model.Enums.PawnColour; 7  8 /** 9  * This class contains the status of Client inside the Server and is responsible for printing UI elements in to the CLI 10  */ 11 public class ClientView { 12  13  /** 14  * Used to contain the game 15  */ 16  private Model model; 17  /** 18  * Used to verify whether the client is connected to the Server 19  */ 20  private boolean isConnected = false; 21  /** 22  * Used to verify whether the client is logged to the Server 23  */ 24  private boolean isLogged = false; 25  /** 26  * Used to verify whether the client has entered a lobby 27  */ 28  private boolean isInLobby = false; 29  /** 30  * Used to verify whether the Game has started 31  */ 32  private boolean gameStarted = false; 33  /** 34  * Used to verify whether the Game has ended 35  */ 36  private boolean gameEnded = false; 37  /** 38  * Used to contain lobby's admin's nickname 39  */ 40  private String admin; 41  /** 42  * Used to contain client's nickname 43  */ 44  private String Nickname; 45  46  /** 47  * Get lobby's admin's nickname 48  * 49  * @return admin's nickname 50  */ 51  public String getAdmin() { 52  return admin; 53  } 54  55  /** 56  * Set Game's admin's nickname 57  * 58  * @param admin String containing admin's nickname 59  */ 60  public void setAdmin(String admin) { 61  this.admin = admin; 62  } 63  64  /** 65  * Get current game 66  * 67  * @return gameBoard representing the game 68  */ 69  public Model getModel() { 70  return this.model; 71  } 72  73  /** 74  * Get whether the game has started or not 75  * 76  * @return true if the game has started, false otherwise 77  */ 78  public boolean getGameStarted() { 79  return this.gameStarted; 80  } 81  82  /** 83  * Set Game's status (started or not) 84  * 85  * @param started boolean representing whether the game has started or not 86  */ 87  public void setGameStarted(boolean started) { 88  this.gameStarted = started; 89  } 90  91  /** 92  * Get whether the game has ended or not 93  * 94  * @return true if the game has ended, false otherwise 95  */ 96  public boolean isGameEnded() { 97  return gameEnded; 98  } 99  100  /** 101  * Set Game's status (ended or not) 102  * 103  * @param gameEnded boolean representing whether the game has ended or not 104  */ 105  public void setGameEnded(boolean gameEnded) { 106  this.gameEnded = gameEnded; 107  } 108  109  /** 110  * Get whether the client has connected to a lobby or not 111  * 112  * @return true if the client has connected to a lobby, false otherwise 113  */ 114  public boolean isInLobby() { 115  return this.isInLobby; 116  } 117  118  /** 119  * Get whether the client has connected to the Server or not 120  * 121  * @return true if the client has connected to the Server, false otherwise 122  */ 123  public boolean isConnected() { 124  return isConnected; 125  } 126  127  /** 128  * Set Client's connection status(connected or not) 129  * 130  * @param connected boolean representing whether the client has connected or not to the server 131  */ 132  public void setConnected(boolean connected) { 133  isConnected = connected; 134  } 135  136  /** 137  * Get whether the client has logged to the Server or not 138  * 139  * @return true if the client has logged to the Server, false otherwise 140  */ 141  public boolean isLogged() { 142  return isLogged; 143  } 144  145  /** 146  * Set Client's logged status inside the server (logged or not) 147  * 148  * @param logged boolean representing whether the client is logged or not 149  */ 150  public void setLogged(boolean logged) { 151  isLogged = logged; 152  } 153  154  /** 155  * Prints all gameBoard's element that the user is allowed to see (Islands, clouds, playerBoards and characterCards) 156  */ 157  public void printView() { 158  printIslandField(); 159  System.out.println("\n"); 160  printGameBoards(); 161  printCharacterCard(); 162  } 163  164  /** 165  * Support method responsible for printing all field's components (islands and clouds) 166  */ 167  private void printIslandField() { 168  //print GameBoard 169  System.out.println(GameUI.draw(this.model)); 170  } 171  172  /** 173  * Support method responsible for printing all players' PlayerBoards 174  */ 175  private void printGameBoards() { 176  System.out.println(Symbols.BACKGROUND + "PLAYERBOARDS"); 177  //simple loop to print playerBoard and its Owner's nickname 178  for (PlayerBoard pb : this.model.getMutablePlayerBoards()) { 179  if (this.getNickname().equals(pb.getNickname())) { 180  System.out.print("Your Playerboard:"); 181  } else { 182  System.out.print(pb.getNickname() + "'s Playerboard"); 183  } 184  if (model.getMutableTurnOrder().getMutableSelectedCard(pb).isPresent()) { 185  System.out.print(" played assistantCard with priority:" + model.getMutableTurnOrder().getMutableSelectedCard(pb).get().getPriority()); 186  } 187  //print PlayerBoard 188  System.out.println(PlayerBoardUI.drawPlayerBoard(pb, this.model)); 189  System.out.println("\n"); 190  } 191  //print current and next player 192  System.out.println(InfoUI.draw(this.model, this.Nickname)); 193  } 194  195  /** 196  * Support method responsible for printing the 3 characterCards 197  */ 198  private void printCharacterCard() { 199  //Print only if the gameMode is Advanced 200  if (this.model.getGameMode() == GameMode.SIMPLE) return; 201  System.out.println("Available CharacterCards:"); 202  for (CharacterCard characterCard : this.model.getCharacterCards()) { 203  //print CharacterCard's number and cost 204  System.out.print("CharacterCard number:" + characterCard.getId() + " cost:" + characterCard.getCost()); 205  //only if the CharacterCard has a stateful effect then print it's content 206  if (characterCard instanceof StatefulEffect) { 207  System.out.print("\t"); 208  // this index is used to identify students position on cards that hold any 209  int indexOfStudentOnCard = 0; 210  for (Object o : ((StatefulEffect) characterCard).getState()) { 211  switch (o) { 212  //if the content is a NoEntryTile then print 'X' 213  case NoEntryTile ignored -> System.out.print(" X "); 214  //if the content is a pawn then print it's colour 215  case PawnColour pawnColour -> { 216  System.out.print(" " + Symbols.colorizeBackgroundStudent(pawnColour, String.valueOf(indexOfStudentOnCard))); 217  indexOfStudentOnCard++; 218  } 219  case default -> System.out.println("Card's object not valid"); 220  } 221  } 222  } 223  System.out.println("\n"); 224  } 225  } 226  227  /** 228  * get Client's nickname 229  * 230  * @return String containing the nickname 231  */ 232  public String getNickname() { 233  return Nickname; 234  } 235  236  /** 237  * Set Client's nickname 238  * 239  * @param nickname String containing Client's nickname 240  */ 241  public void setNickname(String nickname) { 242  this.Nickname = nickname; 243  } 244  245  public void disconnectViewFromServer() { 246  disconnectView(); 247  setConnected(false); 248  } 249  250  /** 251  * Method to disconnect the view from lobby (when the game ends or is closed for any reason) 252  */ 253  public void disconnectView() { 254  setIsInLobby(false); 255  setAdmin(null); 256  setGame(null); 257  setGameStarted(false); 258  } 259  260  /** 261  * Set Client's status inside a lobby (connected to a lobby or not) 262  * 263  * @param inLobby boolean representing whether the client is in lobby or not 264  */ 265  public void setIsInLobby(boolean inLobby) { 266  this.isInLobby = inLobby; 267  } 268  269  /** 270  * Set game's model 271  * 272  * @param game GameBoard containing game's model 273  */ 274  public void setGame(Model game) { 275  this.model = game; 276  } 277  278  279 } 280  281