Skip to content

Commit

Permalink
Add comments for JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
CPandaS committed Jul 5, 2019
1 parent d6ade25 commit 903a5ad
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 23 deletions.
69 changes: 67 additions & 2 deletions src/main/java/it/polimi/ingsw/view/cli/ViewCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,37 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* The CLI view
*/
public class ViewCLI extends LocalView implements Runnable {
/**
* Logger
*/
private static final Logger LOG = Logger.getLogger(ViewCLI.class.getName());

/**
* Standings line
*/
private static final String STANDINGS_LINE = "{0}) {1} ({2} punti)";

/**
* Scanner
*/
private Scanner scanner;
/**
* Model
*/
private MiniModel model;

/**
* Constructor
*/
public ViewCLI() {
scanner = new Scanner(System.in);
}

/**
* Run the CLI
*/
@Override
public synchronized void run() {
String connection;
Expand Down Expand Up @@ -72,6 +91,14 @@ public synchronized void run() {
println(Dialogs.getDialog(Dialog.WAIT_MATCH_START));
}

/**
* Select object
* @param objUuid List of the UUID of the objects.
* @param min Minimum objects.
* @param max Maximum of objects.
* @param dialog The dialog type
* @return List of selected objects
*/
@Override
public synchronized ArrayList<String> selectObject(ArrayList<String> objUuid, int min, int max, Dialog dialog) {
// Print options
Expand Down Expand Up @@ -118,11 +145,19 @@ public synchronized ArrayList<String> selectObject(ArrayList<String> objUuid, in
return new ArrayList<>(selectedUuid);
}

/**
* Show message
* @param message Massage to be shown.
*/
@Override
public synchronized void showMessage(String message) {
println(message);
}

/**
* Update the model
* @param model Updated model.
*/
@Override
public synchronized void updateModel(MiniModel model) {
// Save new model
Expand All @@ -138,6 +173,10 @@ public synchronized void updateModel(MiniModel model) {
}
}

/**
* Notify the end of the match
* @param standings Final Standings of the game.
*/
@Override
public synchronized void notifyEndMatch(ArrayList<StandingsItem> standings) {
cls();
Expand All @@ -152,10 +191,18 @@ public synchronized void notifyEndMatch(ArrayList<StandingsItem> standings) {
}
}

/**
* Read a line
* @return The next line to read
*/
private synchronized String readLine() {
return scanner.nextLine();
}

/**
* Read int
* @return read an integer value
*/
private synchronized int readInt() {
int integer = 0;
boolean valid = false;
Expand All @@ -174,22 +221,40 @@ private synchronized int readInt() {
return integer;
}

/**
* Clear the screen
*/
private synchronized void cls() {
println(ColorCLI.ANSI_CLS);
}

/**
* Print dialog
* @param dialog The dialog
* @param params The parameter to fill the dialog
*/
private synchronized void printDialog(Dialog dialog, String ...params) {
println(Dialogs.getDialog(dialog, params));
}

/**
* Print a string and go to the next line
* @param s the string to print
*/
private synchronized void println(String s) {
System.out.println(s);
}

/**
* Print no string and go to the next line
*/
private void println() {
println("");
}

/**
* Disconnect
*/
@Override
public void disconnect() {
super.disconnect();
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/it/polimi/ingsw/view/cli/component/BoardCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the board in the CLI
*/
public class BoardCLI {
/**
* Length of the square
*/
public static final int LENGTH = 25;

/**
* Board to represent
*/
private MiniBoard miniBoard;

/**
* Constructor
* @param miniBoard Board to represent
*/
public BoardCLI(MiniBoard miniBoard){
this.miniBoard=miniBoard;
}

/**
* Generate a List of string to represent the board whit character
* @return the list of string
*/
public List<String> viewBoard() {
MiniSquare ms;
List<String> outList = new ArrayList<>();
Expand Down Expand Up @@ -63,6 +79,11 @@ public List<String> viewBoard() {
return outList;
}

/**
* Generate the square
* @param ms the square to generate
* @return the list of string that represents the square
*/
public List<String> viewSquare(MiniSquare ms) {
ArrayList<String> outList = new ArrayList<>();
String out ;
Expand Down Expand Up @@ -155,6 +176,12 @@ else if (ms.getClass() == MiniStandardSquare.class) {
return outList;
}

/**
* Search a square knowing its coordinate
* @param list List of squares to search in
* @param coordinate Coordinate of the square to search
* @return the square to find
*/
private MiniSquare searchSquare(List<MiniSquare> list, Coordinate coordinate) {
for (MiniSquare ms : list) {
if (coordinate.equals(ms.getCoordinates()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the game board in the CLI
*/
public class GameBoardCLI {

/**
* The board CLI
*/
private BoardCLI boardCLI;
/**
* The game board to represent
*/
private MiniGameBoard miniGameBoard;

/**
* Constructor
* @param miniGameBoard the game board to represent
*/
public GameBoardCLI(MiniGameBoard miniGameBoard){
this.miniGameBoard = miniGameBoard;
this.boardCLI = new BoardCLI(miniGameBoard.getBoard());
}

/**
* Generate the list of strings that represent the game board
* @return list of strings that represent the game board
*/
public List<String> viewGameBoard(){
ArrayList<String> outLIst = new ArrayList<>();
String out=" ";
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/it/polimi/ingsw/view/cli/component/MatchCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the Match in the CLI
*/
public class MatchCLI {
/**
* The game board CLI
*/
private GameBoardCLI gameBoardCLI;
/**
* List of players
*/
private ArrayList<PlayerCLI> playerCLI;
/**
* Match to represent
*/
private MiniMatch miniMatch;

/**
* Constructor
* @param miniMatch match to represent
*/
public MatchCLI(MiniMatch miniMatch) {
this.miniMatch = miniMatch;
this.gameBoardCLI = new GameBoardCLI(miniMatch.getGameBoard());
Expand All @@ -21,6 +37,10 @@ public MatchCLI(MiniMatch miniMatch) {
}
}

/**
* Generate the list of strings that represent the match
* @return list of strings that represent the match
*/
public List<String> viewMatch(){
List<String> outList = new ArrayList<>();
List<String> squareList = new ArrayList<>();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/it/polimi/ingsw/view/cli/component/ModelCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,38 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the model in the CLI
*/
public class ModelCLI {
/**
* Model to represent
*/
private MiniModel miniModel;
/**
* Match CLI
*/
private MatchCLI matchCLI;
/**
* Player CLI
*/
private PlayerCLI playerCLI;

/**
* Constructor
* @param miniModel the model to represent
*/
public ModelCLI(MiniModel miniModel) {
this.miniModel = miniModel;
this.playerCLI = new PlayerCLI(miniModel.getMyMiniPlayer(), miniModel.getMyPowerUps());
miniModel.getMatch().getPlayers().remove(miniModel.getMyMiniPlayer());
this.matchCLI = new MatchCLI(miniModel.getMatch());
}

/**
* Generate the list of strings that represent the model
* @return list of strings that represent the model
*/
public List<String> viewModel(){
List<String> outList = new ArrayList<>();
String out;
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/it/polimi/ingsw/view/cli/component/PlayerCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,32 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the player in the CLI
*/
public class PlayerCLI {

/**
* Length of the container
*/
static final int LENGTH = 25;

/**
* Player to represent
*/
private MiniPlayer player;
/**
* List of player's power-ups
*/
private List<MiniPowerUp> powerUp;
/**
* Weapon CLI
*/
private ArrayList<WeaponCLI> weaponCLI;

/**
* Constructor
* @param miniPlayer the player to represent
* @param powerUp the list of player's power-ups
*/
PlayerCLI(MiniPlayer miniPlayer, List<MiniPowerUp> powerUp){
this.player = miniPlayer;
this.powerUp = powerUp;
Expand All @@ -28,6 +46,10 @@ public class PlayerCLI {
}
}

/**
* Generate the list of strings that represent the player
* @return list of strings that represent the player
*/
public synchronized List<String> viewPlayer(){
int space;
String out;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/it/polimi/ingsw/view/cli/component/WeaponCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represent the weapon in the CLI
*/
public class WeaponCLI {
/**
* The weapon to represent
*/
private MiniWeapon miniWeapon;
/**
* Length of the space
*/
private static final int LENGTH = 25 ;

/**
* Constructor
* @param miniWeapon the weapon to represent
*/
public WeaponCLI(MiniWeapon miniWeapon) {
this.miniWeapon = miniWeapon;
}

/**
* Generate the list of strings that represent the weapon
* @return list of strings that represent the weapon
*/
public List<String> viewWeapon(){
String out;
int space;
Expand Down
Loading

0 comments on commit 903a5ad

Please sign in to comment.