diff --git a/core/src/be/ac/umons/slay/g02/gui/Main.java b/core/src/be/ac/umons/slay/g02/gui/Main.java index 274cd22..ef433aa 100644 --- a/core/src/be/ac/umons/slay/g02/gui/Main.java +++ b/core/src/be/ac/umons/slay/g02/gui/Main.java @@ -21,7 +21,7 @@ import be.ac.umons.slay.g02.players.StatsLoader; /** - * gere les changements d'ecran TODO + * Class initializing some values and managing screen changes */ public class Main extends Game { public static Skin skinSgx; @@ -50,31 +50,31 @@ public class Main extends Game { private static boolean isStatsLoad = false; public static ArrayList tabPlayers; - // Used for unit testing + // Used for unit testing private static final String DATA = "data/"; private static String nameFile = "PlayerData3.xml"; public static boolean isInTest = false; /** - * TODO + * Sets the name of the xml file used to store the data of players with an account * - * @param nameFile + * @param nameFile the file name */ public static void setNameFile(String nameFile) { Main.nameFile = nameFile; } /** - * TODO + * Gets the name of the xml file used to store the data of players with an account * - * @return + * @return the path to the file */ public static String getNameFile() { return DATA + nameFile; } /** - * TODO + * Initializes some values then brings the user to the menu */ @Override public void create() { @@ -144,6 +144,8 @@ public void create() { tabPlayers = statsLoader.createTab(); isStatsLoad = true; } + + // Creates the menu this.setScreen(new Menu(this)); if (Gdx.app.getType() != Application.ApplicationType.Android) { @@ -166,12 +168,6 @@ public void render() { public void resize(int width, int height) { SCREEN_WIDTH = width; SCREEN_HEIGHT = height; - if (SCREEN_WIDTH > SCREEN_HEIGHT) { - //skinSgx.getFont("title").getData().setScale(SCREEN_WIDTH * 0.8f / VIRTUAL_WIDTH, SCREEN_HEIGHT * 0.8f / VIRTUAL_HEIGHT); - //skinSgxTable.getFont("font").getData().setScale(SCREEN_WIDTH * 1f / VIRTUAL_WIDTH, SCREEN_HEIGHT * 1f / VIRTUAL_HEIGHT); - //skinSgxTable.getFont("title").getData().setScale(SCREEN_WIDTH * 0.9f / VIRTUAL_WIDTH, SCREEN_HEIGHT * 0.9f / VIRTUAL_HEIGHT); - } - //stage.getViewport().setScreenBounds(0, 0, width, height); this.getScreen().resize(width, height); } diff --git a/core/src/be/ac/umons/slay/g02/gui/screens/EndGame.java b/core/src/be/ac/umons/slay/g02/gui/screens/EndGame.java index edcbf5c..b3a7b4f 100644 --- a/core/src/be/ac/umons/slay/g02/gui/screens/EndGame.java +++ b/core/src/be/ac/umons/slay/g02/gui/screens/EndGame.java @@ -44,7 +44,7 @@ public class EndGame implements Screen { /** * TODO * - * @param aGame + * @param aGame the instance of Game created in class Main * @param winner * @param numberHuman */ diff --git a/core/src/be/ac/umons/slay/g02/gui/screens/GameScreen.java b/core/src/be/ac/umons/slay/g02/gui/screens/GameScreen.java index 1388880..36f93fa 100644 --- a/core/src/be/ac/umons/slay/g02/gui/screens/GameScreen.java +++ b/core/src/be/ac/umons/slay/g02/gui/screens/GameScreen.java @@ -73,7 +73,7 @@ import static java.lang.StrictMath.sqrt; /** - * TODO classe qui affiche l'interface pendant une partie + * Class displaying the game */ public class GameScreen implements Screen { private Game game; @@ -91,6 +91,7 @@ public class GameScreen implements Screen { private ImageButton buttonL2; private ImageButton buttonL3; private ImageButton buttonChest; + private ImageButton lastButtonCLicked; private CheckBox checkboxPlayer1; private CheckBox checkboxPlayer2; @@ -129,8 +130,9 @@ public class GameScreen implements Screen { private int translateY; private int nbreH; private boolean AIisPaused = false; - private boolean endPlay = false; // partie continue tant que faux - private ImageButton lastButtonCLicked; + + // The game continues while as long as it is false + private boolean endPlay = false; private int worldW; private int worldH; @@ -138,10 +140,10 @@ public class GameScreen implements Screen { private String levelName; /** - * TODO + * Class constructor initializing some values * - * @param aGame - * @param levelName + * @param aGame the instance of Game created in class Main + * @param levelName the level name */ GameScreen(Game aGame, String levelName, int numberHumans) { game = aGame; @@ -155,10 +157,12 @@ public class GameScreen implements Screen { } /** - * TODO + * Creates the world and the interface */ private void init() { try { + // Creates the world : + camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); LevelLoader.Map lvlLoader = LevelLoader.load(levelName, numberHumans); level = lvlLoader.getLevel(); @@ -174,7 +178,7 @@ private void init() { size = prop.get("hexsidelength", Integer.class); errorOffset = size * sqrt(3) - round(size * sqrt(3)); - // Chargement des couches utiles et du tileset + // Loads the useful layers and the tileset territories = (TiledMapTileLayer) map.getLayers().get("Territories"); entities = (TiledMapTileLayer) map.getLayers().get("Entities"); effects = (TiledMapTileLayer) map.getLayers().get("Effects"); @@ -197,14 +201,13 @@ private void init() { camera.translate(-translateX, -translateY, 0); } catch (Exception e) { - new Exception(/*TODO*/); + game.setScreen(new LevelSelection(game)); } + + // Creates the interface loadButtons(); } - /** - * TODO - */ private void handleInput() { //TODO Bloquer dépassements (trop zoom, trop à gauche ...) if (Gdx.input.isKeyPressed(Input.Keys.A) || Gdx.input.isKeyPressed(Input.Keys.MINUS)) { changeZoom(0.02f); @@ -235,15 +238,14 @@ void changeZoom(float delta) { } /** - * TODO + * Displays the pause window */ private void showPauseWindow() { int CORNER_SIZE = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT); windowPause.clear(); - windowPause.setSize( CORNER_SIZE / 2, CORNER_SIZE / 2); + windowPause.setSize(CORNER_SIZE / 2, CORNER_SIZE / 2); windowPause.setPosition(SCREEN_WIDTH / 2 - windowPause.getWidth() / 2, SCREEN_HEIGHT / 2 - windowPause.getHeight() / 2); windowPause.setMovable(false); - // place le titre de la fenetre au milieu windowPause.getTitleTable().padLeft(windowPause.getWidth() / 2 - windowPause.getTitleLabel().getWidth() / 2); windowPause.setVisible(true); @@ -282,15 +284,15 @@ public void clicked(InputEvent event, float x, float y) { } /** - * TODO + * Displays the quit window */ private void showWindowQuit() { int CORNER_SIZE = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT); + windowQuit.clear(); windowQuit.setSize(CORNER_SIZE / 4, CORNER_SIZE / 4); windowQuit.setPosition(SCREEN_WIDTH / 2 - windowQuit.getWidth() / 2, SCREEN_HEIGHT / 2 - windowQuit.getHeight() / 2); windowQuit.setMovable(false); - // place le titre de la fenetre au milieu windowQuit.getTitleTable().padLeft(windowQuit.getWidth() / 2 - windowQuit.getTitleLabel().getWidth() / 2); Table table = new Table(); @@ -360,14 +362,16 @@ public void render(float delta) { /** * Updates all stats for winner and loser (if logged) + * If the winner's name is equal to the player for whom the statistics are updated then we + * increment the number of wins, otherwise we increment the number of defeats * - * @param winner TODO + * @param winner the winner of the game */ private void updatePlayerStats(Player winner) { // Player 1 - if ((prefs.getBoolean("isPlayer1Logged")) && (getPlayers()[0].getName().equals(player1.getName())|| + if ((prefs.getBoolean("isPlayer1Logged")) && (getPlayers()[0].getName().equals(player1.getName()) || getPlayers()[1].getName().equals(player1.getName()))) { - + // Number of games ++ updatePlayerGames(player1); @@ -388,9 +392,9 @@ private void updatePlayerStats(Player winner) { } } // Player 2 - if ((prefs.getBoolean("isPlayer2Logged")) && (getPlayers()[1].getName().equals(player2.getName())|| - getPlayers()[0].getName().equals(player2.getName())) ) { - + if ((prefs.getBoolean("isPlayer2Logged")) && (getPlayers()[1].getName().equals(player2.getName()) || + getPlayers()[0].getName().equals(player2.getName()))) { + // Number of games ++ updatePlayerGames(player2); @@ -414,7 +418,7 @@ private void updatePlayerStats(Player winner) { /** * on incrémente pour globalstats et le levelstats du niveau joué * - * @param player TODO + * @param player TODO */ private void updatePlayerGames(HumanPlayer player) { player.getGlobalStats().incrementStatInMap(player.getGlobalStats().getStats(), Statistics.GAMES); @@ -425,7 +429,7 @@ private void updatePlayerGames(HumanPlayer player) { /** * on incrémente pour globalstats et le levelstats du niveau joué * - * @param player TODO + * @param player TODO */ private void updatePlayerWins(HumanPlayer player) { player.getGlobalStats().incrementStatInMap(player.getGlobalStats().getStats(), Statistics.WINS); @@ -436,7 +440,7 @@ private void updatePlayerWins(HumanPlayer player) { /** * on incrémente pour globalstats et le levelstats du niveau joué * - * @param player TODO + * @param player TODO */ private void updatePlayerDefeats(HumanPlayer player) { player.getGlobalStats().incrementStatInMap(player.getGlobalStats().getStats(), Statistics.DEFEATS); @@ -447,7 +451,7 @@ private void updatePlayerDefeats(HumanPlayer player) { /** * on met à jour pour globalstats et le levelstats du niveau joué puis on calcule le score (pour le niveau joué) * - * @param player TODO + * @param player TODO */ private void updatePlayerScore(HumanPlayer player, boolean hasWon) { player.getListLevelStats(LevelSelection.getCurrentIslandNumber()).updateStats(); @@ -455,25 +459,18 @@ private void updatePlayerScore(HumanPlayer player, boolean hasWon) { // The score is calculated with the global statistics to be displayed in the hall of fame int score = player.getGlobalStats().calculateScore(hasWon); - int scoreBefore=player.getGlobalStats().getScore(); - player.getGlobalStats().setScore(score+scoreBefore); - + int scoreBefore = player.getGlobalStats().getScore(); + player.getGlobalStats().setScore(score + scoreBefore); + saveStatsPlayer(player); // Resets the values used for calculations resetCurrentStats(player); } - /** - * TODO - * - * @param x - * @param y - * @return - */ private Coordinate getCoordinate(float x, float y) { Vector2 vect = viewport.unproject(new Vector2(x, y)); - // Bien mettre le système d'axe + // Adjusts the axis system int offset = (int) (vect.y / size * errorOffset); vect.set((int) (vect.x - (tileW / 2)), (int) (vect.y - (tileH) + offset)); @@ -481,7 +478,7 @@ private Coordinate getCoordinate(float x, float y) { } /** - * TODO + * TODO * * @param x * @param y @@ -494,7 +491,7 @@ void onTap(float x, float y) { if (level.isInLevel(clickPos)) { Tile clickedTile = level.get(clickPos); - // Change state if needed + // Changes state if needed switch (click) { case NOTHING_SELECTED: if (clickedTile.getTerritory() != null && !(clickedTile.getEntity() instanceof Soldier) && @@ -533,20 +530,22 @@ void onTap(float x, float y) { break; } showEffects(clickPos); - if(clickedTile.getType() == TileType.NEUTRAL) { - previousClick = clickPos; // Retenir dernière position que quand click dans le niveau et sur tile neutre + + if (clickedTile.getType() == TileType.NEUTRAL) { + // Remembers last position only when clicking in the map and on neutral tile + previousClick = clickPos; } } } } /** - * TODO + * TODO * * @param clickPos */ private void showEffects(Coordinate clickPos) { - // Show effects + // Shows effects EffectsManagement.eraseCells(effects); switch (click) { @@ -557,8 +556,10 @@ private void showEffects(Coordinate clickPos) { break; case ON_TERRITORY: - // If we click on a territory but not on a soldier, tiles from that territory - // have to be highlighted and we show the market for this territory + /* + If we click on a territory but not on a soldier, tiles from that territory + have to be highlighted and we show the market for this territory + */ if (level.get(clickPos).getTerritory().getOwner().equals(level.getCurrentPlayer())) { List listTerr = level.neighbourTilesInSameTerritory(clickPos); EffectsManagement.highlightCells(effects, listTerr, tileMap.get("WHITE_HIGHLIGHT")); @@ -589,7 +590,7 @@ private void showEffects(Coordinate clickPos) { } /** - * TODO + * TODO * * @param c * @param hidden @@ -619,7 +620,7 @@ private void showMarket(Coordinate c, boolean hidden) { } /** - * TODO + * TODO * * @param isShown * @param isVisibleL @@ -640,11 +641,11 @@ private void changeMarketDisplay(boolean isShown, boolean isVisibleL, ImageButto /** * Displays the coins of the selected territory and its income * - * @param c - * @param hidden + * @param c the coordinate of the territory on which the player has clicked + * @param isHidden true if it has to be hidden, false otherwise */ - private void showCoins(Coordinate c, boolean hidden) { - if (hidden) { + private void showCoins(Coordinate c, boolean isHidden) { + if (isHidden) { buttonChest.setVisible(false); labelCoins.setVisible(false); labelIncome.setVisible(false); @@ -666,31 +667,37 @@ private void showCoins(Coordinate c, boolean hidden) { private void loadLevel() { showNextTurnEffects(); if (level.getCurrentPlayer() instanceof AI && !AIisPaused) { - boolean hasWon = ((AI) level.getCurrentPlayer()).play(level.getCurrentPlayer(), true); // true = il y a un gagnant - if (!hasWon) { - endPlay = true; // Signale fin de partie - } + // There is a winner + boolean hasWon = ((AI) level.getCurrentPlayer()).play(level.getCurrentPlayer(), true); + if (!hasWon) + // Indicates the end of the game + endPlay = true; } + // Goes through each cell of the table of the logical part for (int i = 0; i < level.width(); i++) { - for (int j = 0; j < level.height(); j++) { // Parcours de chaque case du tableau de la partie logique + for (int j = 0; j < level.height(); j++) { Tile tile = level.get(i, j); - if (tile.getEntity() != null) { // Si la case contient une entité, la rajouter à l'interface graphique + // If there is an entity in the cell, it is added to the graphical interface + if (tile.getEntity() != null) { TiledMapTile image = tileMap.get(tile.getEntity().getName().toUpperCase()); HexManagement.drawTile(new Coordinate(i, j), image, entities); - } else { // Il n'y a pas ou plus d'entité présente dans la case - if (entities.getCell(i, j) != null) { // Si la cellule n'est pas encore vide dans l'interface graphique, la vider + } + // There is no more entity in the cell + else { + // The cell is cleared if it is not empty in the graphical interface + if (entities.getCell(i, j) != null) entities.setCell(i, j, new TiledMapTileLayer.Cell()); - } } if (tile.getTerritory() != null) { // Si la case appartient à un territoire, le rajouter à l'interface graphique TiledMapTile image = tileMap.get(tile.getTerritory().getOwner().getColor().getName()); HexManagement.drawTile(new Coordinate(i, j), image, territories); - - } else { // Il n'y a pas ou plus de territoire présent sur la case - if (territories.getCell(i, j) != null) { // Si la cellule n'est pas encore vide dans l'interface graphique, la vider + } + // There is no more territory on the cell + else { + // The cell is cleared if it is not empty in the graphical interface + if (territories.getCell(i, j) != null) territories.setCell(i, j, new TiledMapTileLayer.Cell()); - } } } } @@ -741,22 +748,19 @@ public void dispose() { } /** - * TODO + traduire en dessous + * Loads the buttons */ private void loadButtons() { int image_corner = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT); hudCam = new OrthographicCamera(); - if (hud == null) { - - //hud = new Stage(new FitViewport(SCREEN_WIDTH, SCREEN_HEIGHT, hudCam)); + if (hud == null) hud = new Stage(new ScreenViewport()); - } else { + else hud.clear(); - } if (numberHumans == 0) { - // Initialisation des boutons + // Initialises speed and pause buttons TextureRegionDrawable imageV4 = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("images/v4.png")))); final ImageButton buttonV4 = new ImageButton(imageV4); TextureRegionDrawable imageV3 = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("images/v3.png")))); @@ -768,8 +772,7 @@ private void loadButtons() { TextureRegionDrawable imagePause = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("images/v0.png")))); final ImageButton buttonV0 = new ImageButton(imagePause); - // Bien positionner les boutons - + // Adjusts speed and pause buttons position float offsetW = 10; float offsetH = buttonV4.getHeight(); buttonV4.setPosition((SCREEN_WIDTH - offsetW) * 96 / 100 + SCREEN_HEIGHT * 1 / 200, offsetH); @@ -782,13 +785,12 @@ private void loadButtons() { offsetW += buttonV0.getWidth() + 10; buttonV0.setPosition((SCREEN_WIDTH - offsetW) * 96 / 100 + SCREEN_HEIGHT * 1 / 200, offsetH); - - if (lastButtonCLicked == null) { + if (lastButtonCLicked == null) makeButtonGreen(true, buttonV3); - } else { + else makeButtonGreen(true, lastButtonCLicked); - } - // Ajouter les actions + + // Adds speed and pause buttons : buttonV4.addListener(new ClickListener() { @Override @@ -866,7 +868,7 @@ public void clicked(InputEvent event, float x, float y) { hud.addActor(buttonV0); } else { - // Adds button Next + // Adds button Next : TextureRegionDrawable imageNext = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("images/next.png")))); buttonNext = new ImageButton(imageNext); @@ -889,7 +891,7 @@ public void clicked(InputEvent event, float x, float y) { }); hud.addActor(buttonNext); } - // Adds button Pause + // Adds button Pause : TextureRegionDrawable imageDots = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("images/dots.png")))); buttonPause = new ImageButton(imageDots); @@ -906,7 +908,7 @@ public void clicked(InputEvent event, float x, float y) { } }); - // Adds entity market + // Adds entity market : TextureRegionDrawable imageL0 = new TextureRegionDrawable(new TextureRegion((new Texture(Gdx.files.internal("images/L0.png"))))); buttonL0 = new ImageButton(imageL0); @@ -977,7 +979,7 @@ public void clicked(InputEvent event, float x, float y) { } }); - // Player 1 + // Player 1 : checkboxPlayer1 = new CheckBox("", skinSgx, "radio"); checkboxPlayer1.getImage().setScale(1.5f); @@ -992,7 +994,7 @@ public void clicked(InputEvent event, float x, float y) { Label labelP1 = new Label(Level.getPlayers()[0].getName(), skinSgx, "title-white"); labelP1.setFontScale(1.2f); - // Player 2 + // Player 2 : checkboxPlayer2 = new CheckBox("", skinSgx, "radio"); checkboxPlayer2.getImage().setScale(1.5f); @@ -1030,23 +1032,23 @@ public void clicked(InputEvent event, float x, float y) { labelWages.setVisible(false); Table screenTablePlayers = new Table(); - - if (SCREEN_WIDTH > SCREEN_HEIGHT && ! (Gdx.app.getType() == Application.ApplicationType.Android)) { - screenTablePlayers.setFillParent(true); - screenTablePlayers.padTop(SCREEN_HEIGHT - (2 * (SCREEN_HEIGHT * 6 / 100) + 3 * SCREEN_HEIGHT * 2 / 100)).left().padLeft(SCREEN_HEIGHT * 2 / 100); - screenTablePlayers.add(checkboxPlayer1).padRight(SCREEN_HEIGHT * 2 / 100 + checkboxPlayer1.getImage().getWidth() / 2.6f).padTop(checkboxPlayer1.getImage().getHeight() * 2 / 3); + + if (SCREEN_WIDTH > SCREEN_HEIGHT && !(Gdx.app.getType() == Application.ApplicationType.Android)) { + screenTablePlayers.setFillParent(true); + screenTablePlayers.padTop(SCREEN_HEIGHT - (2 * (SCREEN_HEIGHT * 6 / 100) + 3 * SCREEN_HEIGHT * 2 / 100)).left().padLeft(SCREEN_HEIGHT * 2 / 100); + screenTablePlayers.add(checkboxPlayer1).padRight(SCREEN_HEIGHT * 2 / 100 + checkboxPlayer1.getImage().getWidth() / 2.6f).padTop(checkboxPlayer1.getImage().getHeight() * 2 / 3); screenTablePlayers.add(avatarP1).height(SCREEN_HEIGHT * 6 / 100).width(SCREEN_HEIGHT * 6 / 100).padRight(SCREEN_HEIGHT * 2 / 100); screenTablePlayers.add(labelP1).left(); } screenTablePlayers.row(); - - if (SCREEN_WIDTH > SCREEN_HEIGHT && ! (Gdx.app.getType() == Application.ApplicationType.Android)) { - screenTablePlayers.add(checkboxPlayer2).padTop(checkboxPlayer1.getImage().getHeight() * 1.7f).padRight(SCREEN_HEIGHT * 2 / 100 + checkboxPlayer1.getImage().getWidth() / 2.6f); + + if (SCREEN_WIDTH > SCREEN_HEIGHT && !(Gdx.app.getType() == Application.ApplicationType.Android)) { + screenTablePlayers.add(checkboxPlayer2).padTop(checkboxPlayer1.getImage().getHeight() * 1.7f).padRight(SCREEN_HEIGHT * 2 / 100 + checkboxPlayer1.getImage().getWidth() / 2.6f); screenTablePlayers.add(avatarP2).height(SCREEN_HEIGHT * 6 / 100).width(SCREEN_HEIGHT * 6 / 100).padTop(SCREEN_HEIGHT * 2 / 100).padRight(SCREEN_HEIGHT * 2 / 100); screenTablePlayers.add(labelP2).left().padTop(SCREEN_HEIGHT * 2 / 100); } Table tableMarket = new Table(); - + if (SCREEN_WIDTH > SCREEN_HEIGHT) { tableMarket.add(buttonL0).padRight(1.5f * buttonL1.getWidth()); tableMarket.add(buttonL1).padRight(1.5f * buttonL1.getWidth()); @@ -1077,7 +1079,7 @@ public void clicked(InputEvent event, float x, float y) { if (SCREEN_WIDTH > SCREEN_HEIGHT) { screenTableMarket.add(tableMarket).padTop(SCREEN_HEIGHT - buttonL0.getHeight()); } else { - screenTableMarket.add(tableMarket).padTop((SCREEN_HEIGHT - buttonL0.getHeight()) / 2 ).padRight(SCREEN_WIDTH - buttonL0.getWidth()); + screenTableMarket.add(tableMarket).padTop((SCREEN_HEIGHT - buttonL0.getHeight()) / 2).padRight(SCREEN_WIDTH - buttonL0.getWidth()); } hud.addActor(buttonPause); hud.addActor(screenTableMarket); @@ -1088,9 +1090,13 @@ public void clicked(InputEvent event, float x, float y) { @Override public boolean keyUp(InputEvent event, int keycode) { if (keycode == Input.Keys.ENTER && !windowPause.isVisible()) { - boolean hasWon = level.nextTurn(); // true = il y a un gagnant + + // True if there is a winner + boolean hasWon = level.nextTurn(); + if (!hasWon) - endPlay = true; // Signale fin de partie + // Indicates the end of the game + endPlay = true; click = ClickState.NOTHING_SELECTED; EffectsManagement.eraseCells(effects); showEffects(previousClick); @@ -1116,7 +1122,10 @@ public boolean keyUp(InputEvent event, int keycode) { } /** - * TODO + * Changes the appearance of the ball before players name in the corner + *

+ * The ball is the player's color and full when it is his turn + * Otherwise, the ball is a white circle */ private void showNextTurnEffects() { if (level.getCurrentPlayer() == getPlayers()[0]) { @@ -1149,17 +1158,12 @@ private void makeButtonGreen(boolean isSelected, ImageButton... buttonL) { } } - /** - * TODO - * - * @return - */ public static Playable getLevel() { return level; } /** - * TODO + * Enumeration of all possible screen states based on what the player has just clicked */ enum ClickState { NOTHING_SELECTED, diff --git a/core/src/be/ac/umons/slay/g02/gui/screens/Menu.java b/core/src/be/ac/umons/slay/g02/gui/screens/Menu.java index ff88b3c..84a074e 100644 --- a/core/src/be/ac/umons/slay/g02/gui/screens/Menu.java +++ b/core/src/be/ac/umons/slay/g02/gui/screens/Menu.java @@ -69,7 +69,7 @@ import static be.ac.umons.slay.g02.gui.Main.tabPlayers; /** - * classe qui affiche le menu principal TODO + * Class displaying the menu */ public class Menu implements Screen { public static Drawable imageRobot = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal(prefs.getString("pathImageRobot"))))); @@ -198,7 +198,6 @@ public class Menu implements Screen { private String playerName; private FileHandle sourceImage; private File selectedFile; - private int buttonCenterHeight; private int buttonCenterGap; private int labelProfileWidth; @@ -206,9 +205,9 @@ public class Menu implements Screen { private int tableCenterPositionY; /** - * TODO + * Initializes the menu * - * @param aGame + * @param aGame the instance of Game created in class Main */ public Menu(Game aGame) { game = aGame; diff --git a/core/src/be/ac/umons/slay/g02/level/Coordinate.java b/core/src/be/ac/umons/slay/g02/level/Coordinate.java index c5abc03..432153e 100644 --- a/core/src/be/ac/umons/slay/g02/level/Coordinate.java +++ b/core/src/be/ac/umons/slay/g02/level/Coordinate.java @@ -1,33 +1,65 @@ package be.ac.umons.slay.g02.level; /** - * TODO + * Class representing coordinates */ public class Coordinate { private int x; private int y; + /** + * Class constructor + * + * @param x X coordinate + * @param y Y coordinate + */ public Coordinate(int x, int y) { this.x = x; this.y = y; } + /** + * Get x coordinate + * + * @return X coordinate + */ public int getX() { return this.x; } + /** + * Get y coordinate + * + * @return Y coordinate + */ public int getY() { return this.y; } + /** + * Set x coordinate + * + * @param x X coordinate to set + */ public void setX(int x) { this.x = x; } + /** + * Set y coordinate + * + * @param y Y coordinate to set + */ public void setY(int y) { this.y = y; } + /** + * Get a table of nearby coordinates at a coordinates + * + * @return Table of nearby coordinates + */ + public Coordinate[] getNeighbors() { // The neighbors are different if we are on an odd or even column.\ if (x % 2 == 0) { @@ -53,6 +85,12 @@ public Coordinate[] getNeighbors() { } } + /** + * Test the equality between this coordinate and another + * + * @param o The object to test + * @return True if equal, false otherwise + */ @Override public boolean equals(Object o) { if (this == o) diff --git a/core/src/be/ac/umons/slay/g02/level/Level.java b/core/src/be/ac/umons/slay/g02/level/Level.java index bcc222d..9caeecb 100644 --- a/core/src/be/ac/umons/slay/g02/level/Level.java +++ b/core/src/be/ac/umons/slay/g02/level/Level.java @@ -85,7 +85,7 @@ public void setPlayers(Player[] players) { } /** - * TODO + * Get the player whose turn it is * * @return */ @@ -184,10 +184,7 @@ else if (prefs != null && prefs.getBoolean("isPlayer2Logged") && currentPlayer.g } /** - * TODO - * - * Teste s il y a un gagnant avant d'Effectuer les actions de changement de tour - * haswon renvoie le gagnant sil y en a un, null sinon + * Before perform turn change actions, verify if there is a winner using the method hasWon * * @return true if there is no winner and the game should be continued */ @@ -610,7 +607,7 @@ private void mergeTerritories(Coordinate pos, List processed) { } /** - * TODO + * Splits the territories */ private void splitTerritories() { /* @@ -712,11 +709,12 @@ private void neighbourTilesInSameTerritory(Coordinate pos, Territory territory, } /** - * TODO + * Count the number of tiles belonging to a player * - * @param player - * @return + * @param player The player whose territories must be searched + * @return Number of tiles belonging to a player */ + public int countTerritories(Player player) { int count = 0; for (int i = 0; i < width; i++) { @@ -737,8 +735,7 @@ public int countTerritories(Player player) { @Override public Player hasWon() { List inGame = new ArrayList(); - for (int i = 0; i < players.length; i++) { - Player player = players[i]; + for (Player player : players) { int n = countTerritories(player); if (n > 0) diff --git a/core/src/be/ac/umons/slay/g02/level/Territory.java b/core/src/be/ac/umons/slay/g02/level/Territory.java index cbaf15d..fbb9b45 100644 --- a/core/src/be/ac/umons/slay/g02/level/Territory.java +++ b/core/src/be/ac/umons/slay/g02/level/Territory.java @@ -33,8 +33,8 @@ public class Territory { /** * Class constructor * - * @param owner TODO - * @param cells + * @param owner The owner of this territory + * @param cells Tiles in the same territory */ public Territory(Player owner, Tile... cells) { this.owner = owner; @@ -45,45 +45,45 @@ public Territory(Player owner, Tile... cells) { } /** - * //TODO + * Get number of coins in this territory * - * @return + * @return Number of coins */ public int getCoins() { return this.coins; } /** - * //TODO + * Modify number of coins * - * @param coins + * @param coins Number of coins to set */ public void setCoins(int coins) { this.coins = coins; } /** - * //TODO + * Get territory incomes * - * @return + * @return Territory incomes */ public int getIncome() { return this.income; } /** - * //TODO + * Get territory wages * - * @return + * @return Territory wages */ public int getWages() { return this.wages; } /** - * //TODO + * Add a tile in this territory * - * @param cell + * @param cell Tile to add */ public void add(Tile cell) { if (cell.getEntity() != StaticEntity.TREE) @@ -99,8 +99,7 @@ public void add(Tile cell) { /** * Removes a cell * - * @param cell //TODO - + * @param cell Tile to remove * @return */ public boolean remove(Tile cell) { @@ -135,10 +134,10 @@ else if (c.getEntity() != null && c.getEntity() == StaticEntity.CAPITAL) { } /** - * //TODO + * Test if this territory has same owner that other territory * - * @param other - * @return + * @param other Other territory + * @return True if same owner, false otherwise */ public boolean hasSameOwner(Territory other) { if (other == null) { @@ -148,9 +147,9 @@ public boolean hasSameOwner(Territory other) { } /** - * //TODO + * Get tiles list of this territory * - * @return + * @return Tiles list */ List getCells() { // TODO should return a copy for encapsulation @@ -170,8 +169,8 @@ public Player getOwner() { * Updates the income and wages of the territory * and makes sure there is one and only one capital on the territory * - * @param removed TODO - * @param added + * @param removed Entity to remove + * @param added Entity to add */ void update(Entity removed, Entity added) { if (removed != StaticEntity.TREE) @@ -334,9 +333,9 @@ boolean buy(Entity e) { } /** - * //TODO + * Get list of capitals in the territory * - * @return + * @return List of capitals in the territory */ private List getCapitals() { List capitals = new ArrayList(); diff --git a/core/src/be/ac/umons/slay/g02/level/Tile.java b/core/src/be/ac/umons/slay/g02/level/Tile.java index b6ff164..42fdf5a 100644 --- a/core/src/be/ac/umons/slay/g02/level/Tile.java +++ b/core/src/be/ac/umons/slay/g02/level/Tile.java @@ -10,35 +10,37 @@ import static be.ac.umons.slay.g02.gui.screens.Menu.player2; /** - * TODO + * Class representing a tile of the game with a type and maybe a territory or an entity */ + public class Tile { private TileType type; private Entity entity; private Territory territory; /** - * TODO + * Constructor with tile type * - * @param type + * @param type The tile type */ + public Tile(TileType type) { this.type = type; } /** - * TODO + * Get the entity contained in the tile * - * @return + * @return Entity contained in the tile */ public Entity getEntity() { return entity; } /** - * TODO + * Get the type of the tile * - * @return + * @return Type of the tile */ public TileType getType() { return type; @@ -129,9 +131,9 @@ else if (prefs != null && prefs.getBoolean("isPlayer2Logged") && (to.getTerritor } /** - * TODO + * Places an entity in the tile and updates the territory data if necessary * - * @param entity + * @param entity The entity to place * @param rec If you should check for changes in income/wages and capitals or not. */ void setEntity(Entity entity, boolean rec) { @@ -143,9 +145,9 @@ void setEntity(Entity entity, boolean rec) { } /** - * TODO + * Sets an entity and checks for changes in income/wages and capitals * - * @param entity + * @param entity the entity */ void setEntity(Entity entity) { setEntity(entity, true); @@ -154,18 +156,18 @@ void setEntity(Entity entity) { /** * Returns true if this cell has this entity in it * - * @param entity TODO - * @return + * @param entity The entity to test + * @return True if this tile has the entity, false otherwise */ boolean contains(Entity entity) { return this.entity == entity; } /** - * TODO + * Checks if the owner of the tile to test is the same as the current one * - * @param other - * @return + * @param other The other tile to test + * @return True if same owner, false otherwise */ boolean hasSameOwner(Tile other) { if (territory == null) @@ -174,10 +176,11 @@ boolean hasSameOwner(Tile other) { } /** - * TODO + * Checks if two territories can merge by checking if they have the same owner, it that is + * the case, they do merge * - * @param other - * @return + * @param other a tile belonging to another territory + * @return true if the territories have merged */ boolean mergeTerritories(Tile other) { if (hasSameOwner(other)) { @@ -190,9 +193,9 @@ boolean mergeTerritories(Tile other) { } /** - * TODO + * Gets the territory of the tile * - * @return + * @return Tile territory */ public Territory getTerritory() { return this.territory; @@ -222,19 +225,14 @@ public void setTerritory(Territory t) { } /** - * TODO + * Tests if there is a territory * - * @return + * @return True if there is a territory, false otherwise */ boolean hasTerritory() { return !(territory == null); } - /** - * TODO - * - * @return - */ @Override public String toString() { return "[" + type.toString() + ":" + entity + ":" + territory + "]"; diff --git a/core/src/be/ac/umons/slay/g02/level/TileType.java b/core/src/be/ac/umons/slay/g02/level/TileType.java index 8fba12a..7736825 100644 --- a/core/src/be/ac/umons/slay/g02/level/TileType.java +++ b/core/src/be/ac/umons/slay/g02/level/TileType.java @@ -1,7 +1,7 @@ package be.ac.umons.slay.g02.level; /** - * TODO + * Possible type for tiles */ public enum TileType { NEUTRAL, diff --git a/core/src/be/ac/umons/slay/g02/players/AI.java b/core/src/be/ac/umons/slay/g02/players/AI.java index 25a49ff..3cb4ab9 100644 --- a/core/src/be/ac/umons/slay/g02/players/AI.java +++ b/core/src/be/ac/umons/slay/g02/players/AI.java @@ -1,7 +1,7 @@ package be.ac.umons.slay.g02.players; /** - * An interface for artificial intelligence + * An interface for artificial intelligence */ public interface AI { boolean play(Player player, boolean forMe); diff --git a/core/src/be/ac/umons/slay/g02/players/AIAdaptive.java b/core/src/be/ac/umons/slay/g02/players/AIAdaptive.java index 2dfb177..0219ae1 100644 --- a/core/src/be/ac/umons/slay/g02/players/AIAdaptive.java +++ b/core/src/be/ac/umons/slay/g02/players/AIAdaptive.java @@ -2,6 +2,7 @@ import java.io.File; import java.util.HashMap; + import be.ac.umons.slay.g02.entities.Soldier; import be.ac.umons.slay.g02.entities.StaticEntity; import be.ac.umons.slay.g02.gui.screens.GameScreen; @@ -51,23 +52,23 @@ public AIAdaptive(Colors color, String name) { public boolean play(Player player, boolean forMe) { level = GameScreen.getLevel(); players = Level.getPlayers(); - int [] scores = scoreCount(); + int[] scores = scoreCount(); int hard = 0; // Random by default - for(int i = 0; i < players.length; i++) { - if(players[i].equals(this)) { - for (int j = 0; j < players.length; j++ ) { - if(i != j) { - if(scores[i]*0.5 > scores[j]) { + for (int i = 0; i < players.length; i++) { + if (players[i].equals(this)) { + for (int j = 0; j < players.length; j++) { + if (i != j) { + if (scores[i] * 0.5 > scores[j]) { // Enemy very loose => Random hard = 0; - } else if(scores[i]*0.75 > scores[j]) { + } else if (scores[i] * 0.75 > scores[j]) { // Enemy loose a bit => Easy hard = 1; - } else if(scores[i] < scores[j]*1.1 && scores[i] > scores[j]*.9) { + } else if (scores[i] < scores[j] * 1.1 && scores[i] > scores[j] * .9) { // Equal to plus or minus 10 percent => Medium hard = 2; - } else if(scores[i] < scores[j]*0.9) { + } else if (scores[i] < scores[j] * 0.9) { // AI loose hard = 3; } @@ -79,13 +80,13 @@ public boolean play(Player player, boolean forMe) { boolean bool; switch (hard) { - case 1 : + case 1: bool = easy.play(this, false); break; - case 2 : + case 2: bool = medium.play(this, false); break; - case 3 : + case 3: bool = advanced.play(this, false); break; default: @@ -106,7 +107,7 @@ private int[] scoreCount() { int[] scores = new int[players.length]; HashMap pl = new HashMap(players.length); - for (int i=0; i territory : allTerritories) { - // Pour chaque territoire tryToAddUnit(territory); - // Déplacement ? for (Coordinate cFrom : territory) { - // Parcours toutes les cases de ce terroire Tile tile = level.get(cFrom); if (tile.getEntity() != null && tile.getEntity() instanceof Soldier) { - // Si il y a un soldat Soldier soldier = (Soldier) tile.getEntity(); if (!soldier.getMoved()) { - // Il ne s'est pas encore déplacé Coordinate cTo = findBestPlace(level.getMoves(cFrom, 4), cFrom, null); if (cTo == null) { - // Default case, get closer to the enemy cTo = AIMethods.searchEnnemy(cFrom, level, this, null); // Soldat null car dplct } if (cTo != null) { @@ -77,12 +71,12 @@ public boolean play(Player player, boolean forMe) { } } } - // finir son tour return level.nextTurn(); } /** * Try to buy each type of unit + * * @param territory List of coordinates representing the territory in which searched */ @@ -109,7 +103,7 @@ private void tryToAddUnit(List territory) { * * @param moves List of accessible coordinates * @param cFrom Original coordinate - * @return The best coordinate if found, null else + * @return The best coordinate if found, null else */ private Coordinate findBestPlace(List moves, Coordinate cFrom, Soldier soldier) { @@ -157,10 +151,10 @@ private Coordinate findBestPlace(List moves, Coordinate cFrom, Soldi * * @param soldier Soldier to buy * @param territory Territory in which the soldier will be placed - * @return True if can buy the soldier, false else + * @return True if can buy the soldier, false else */ - private boolean canBuy (Soldier soldier, Territory territory) { + private boolean canBuy(Soldier soldier, Territory territory) { if (territory.canBuy(soldier)) { // Coins remaining after purchase int rest = territory.getCoins() - soldier.getPrice() + territory.getIncome(); @@ -177,10 +171,10 @@ private boolean canBuy (Soldier soldier, Territory territory) { * @param sold1 Soldier to merge * @param sold2 Soldier to merge * @param territory Territory in which soldiers are - * @return True if can fusion the soldier, false else + * @return True if can fusion the soldier, false else */ - private boolean canFusion (Soldier sold1, Soldier sold2, Territory territory) { + private boolean canFusion(Soldier sold1, Soldier sold2, Territory territory) { int newlvl = sold1.getSoldierLevel().getLevel() + sold2.getSoldierLevel().getLevel(); //Salary for one turn int cost = SoldierLevel.fromLevel(newlvl).getCost(); diff --git a/core/src/be/ac/umons/slay/g02/players/AIEasy.java b/core/src/be/ac/umons/slay/g02/players/AIEasy.java index d61b2f3..b09fece 100644 --- a/core/src/be/ac/umons/slay/g02/players/AIEasy.java +++ b/core/src/be/ac/umons/slay/g02/players/AIEasy.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.List; import java.util.Random; + import be.ac.umons.slay.g02.entities.Soldier; import be.ac.umons.slay.g02.entities.SoldierLevel; import be.ac.umons.slay.g02.gui.screens.GameScreen; @@ -24,6 +25,7 @@ public class AIEasy extends Player implements AI { /** * Constructor of the class, initiating its name, its color and the path of its avatar + * * @param color Player color * @param name Player name */ @@ -77,6 +79,7 @@ public boolean play(Player player, boolean forMe) { /** * Try to buy weak units + * * @param territory List of coordinates representing the territory in which searched */ @@ -100,7 +103,7 @@ private void tryToAddUnit(List territory, int n) { * * @param moves List of accessible coordinates * @param cFrom Original coordinate - * @return The best coordinate if found, null else + * @return The best coordinate if found, null else */ private Coordinate findBestPlace(List moves, Coordinate cFrom) { diff --git a/core/src/be/ac/umons/slay/g02/players/AIMedium.java b/core/src/be/ac/umons/slay/g02/players/AIMedium.java index 8a23332..1467b29 100644 --- a/core/src/be/ac/umons/slay/g02/players/AIMedium.java +++ b/core/src/be/ac/umons/slay/g02/players/AIMedium.java @@ -1,13 +1,10 @@ package be.ac.umons.slay.g02.players; import java.io.File; -import java.util.ArrayList; import java.util.List; -import java.util.Random; import be.ac.umons.slay.g02.entities.Soldier; import be.ac.umons.slay.g02.entities.SoldierLevel; -import be.ac.umons.slay.g02.entities.StaticEntity; import be.ac.umons.slay.g02.gui.screens.GameScreen; import be.ac.umons.slay.g02.level.Coordinate; import be.ac.umons.slay.g02.level.Playable; @@ -28,6 +25,7 @@ public class AIMedium extends Player implements AI { /** * Constructor of the class, initiating its name, its color and the path of its avatar + * * @param color Player color * @param name Player name */ @@ -55,21 +53,15 @@ public boolean play(Player player, boolean forMe) { allTerritories = AIMethods.loadTerritories(level, player, false); } for (List territory : allTerritories) { - // Pour chaque territoire tryToAddUnit(territory); - // Déplacement ? for (Coordinate cFrom : territory) { - // Parcours toutes les cases de ce terroire Tile tile = level.get(cFrom); if (tile.getEntity() != null && tile.getEntity() instanceof Soldier) { - // Si il y a un soldat Soldier soldier = (Soldier) tile.getEntity(); if (!soldier.getMoved()) { - // Il ne s'est pas encore déplacé Coordinate cTo = findBestPlace(level.getMoves(cFrom, 4), cFrom, null); if (cTo == null) { - // Default case, get closer to the enemy cTo = AIMethods.searchEnnemy(cFrom, level, this, null); // Soldat null car dplct } if (cTo != null) { @@ -79,12 +71,12 @@ public boolean play(Player player, boolean forMe) { } } } - // finir son tour return level.nextTurn(); } /** * Try to buy each type of unit + * * @param territory List of coordinates representing the territory in which searched */ @@ -111,7 +103,7 @@ private void tryToAddUnit(List territory) { * * @param moves List of accessible coordinates * @param cFrom Original coordinate - * @return The best coordinate if found, null else + * @return The best coordinate if found, null else */ private Coordinate findBestPlace(List moves, Coordinate cFrom, Soldier soldier) { @@ -159,10 +151,10 @@ private Coordinate findBestPlace(List moves, Coordinate cFrom, Soldi * * @param soldier Soldier to buy * @param territory Territory in which the soldier will be placed - * @return True if can buy the soldier, false else + * @return True if can buy the soldier, false else */ - private boolean canBuy (Soldier soldier, Territory territory) { + private boolean canBuy(Soldier soldier, Territory territory) { if (territory != null && territory.canBuy(soldier)) { // Coins remaining after purchase int rest = territory.getCoins() - soldier.getPrice(); @@ -179,10 +171,10 @@ private boolean canBuy (Soldier soldier, Territory territory) { * @param sold1 Soldier to merge * @param sold2 Soldier to merge * @param territory Territory in which soldiers are - * @return True if can fusion the soldier, false else + * @return True if can fusion the soldier, false else */ - private boolean canFusion (Soldier sold1, Soldier sold2, Territory territory) { + private boolean canFusion(Soldier sold1, Soldier sold2, Territory territory) { int newlvl = sold1.getSoldierLevel().getLevel() + sold2.getSoldierLevel().getLevel(); int cost = SoldierLevel.fromLevel(newlvl).getCost(); return territory.getCoins() > cost; diff --git a/core/src/be/ac/umons/slay/g02/players/AIMethods.java b/core/src/be/ac/umons/slay/g02/players/AIMethods.java index 8e6af90..892e822 100644 --- a/core/src/be/ac/umons/slay/g02/players/AIMethods.java +++ b/core/src/be/ac/umons/slay/g02/players/AIMethods.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; + import be.ac.umons.slay.g02.entities.Soldier; import be.ac.umons.slay.g02.entities.StaticEntity; import be.ac.umons.slay.g02.gui.screens.HexManagement; @@ -19,18 +20,18 @@ public class AIMethods { * Number of milliseconds that artificial intelligence must wait before playing */ - private static int speed = 333; // 3 tours / seconde + private static int speed = 333; // Three turns by second /** * Search all territories of a player or his enemies * - * @param level Level in which searched - * @param player Player starting the search - * @param searchEnemy Boolean determining whether to search for the player's (false) or enemy's territories (true) - * @return List of all territories represented by the list of coordinates belonging to it + * @param level Level in which searched + * @param player Player starting the search + * @param searchEnemy Boolean determining whether to search for the player's (false) or enemy's territories (true) + * @return List of all territories represented by the list of coordinates belonging to it */ - static List> loadTerritories (Playable level, Player player, boolean searchEnemy) { + static List> loadTerritories(Playable level, Player player, boolean searchEnemy) { List> allTerritories = new ArrayList>(); List visited = new ArrayList(); @@ -75,39 +76,36 @@ static void sleep() { /** * Change speed value - * @param sp New speed value + * + * @param sp New speed value */ - public static void setSpeed (int sp) { + public static void setSpeed(int sp) { speed = sp; } /** * Search for trees to be cut in the player's territory * - * @param level Level in which searched - * @param moves List of coordinates in which to search - * @param cFrom Original coordinate - * @param player Player starting the search - * @return Coordinate of a tile containing a tree to cut, null otherwise + * @param level Level in which searched + * @param moves List of coordinates in which to search + * @param cFrom Original coordinate + * @param player Player starting the search + * @return Coordinate of a tile containing a tree to cut, null otherwise */ - static Coordinate chopTree (Playable level, List moves, Coordinate cFrom, Player player) { + static Coordinate chopTree(Playable level, List moves, Coordinate cFrom, Player player) { for (Coordinate cTo : moves) { if (!cFrom.equals(cTo)) { - // Parcours de toutes les cases où mon soldat peut être placé + // Walk through all the boxes where my soldier can be placed Tile current = level.get(cTo); - // Récupère la tuile correspondante if (current.getTerritory() != null) { - // Il y a un territoire - if (current.getTerritory().getOwner().equals(player)) { - // Même territoire + // Same territory if (current.getEntity() != null) { - // Il y a une entité + // There is a entity if (current.getEntity() == StaticEntity.TREE) { - // D'abord sur les arbres return cTo; } } @@ -121,18 +119,16 @@ static Coordinate chopTree (Playable level, List moves, Coordinate c /** * Look for neutral tile to occupy * - * @param level Level in which searched - * @param moves List of coordinates in which to search - * @param cFrom Original coordinate - * @param player Player starting the search - * @return Coordinate of a neutral tile, null otherwise + * @param level Level in which searched + * @param moves List of coordinates in which to search + * @param cFrom Original coordinate + * @param player Player starting the search + * @return Coordinate of a neutral tile, null otherwise */ - static Coordinate captureNeutral (Playable level, List moves, Coordinate cFrom, Player player) { + static Coordinate captureNeutral(Playable level, List moves, Coordinate cFrom, Player player) { for (Coordinate cTo : moves) { if (!cFrom.equals(cTo)) { - // Parcours de toutes les cases où mon soldat peut être placé Tile current = level.get(cTo); - // Récupère la tuile correspondante if (current.getTerritory() == null) { return cTo; } @@ -144,14 +140,14 @@ static Coordinate captureNeutral (Playable level, List moves, Coordi /** * Search for graves to be cut in the player's territory * - * @param level Level in which searched - * @param moves List of coordinates in which to search - * @param cFrom Original coordinate - * @param player Player starting the search - * @return Coordinate of a tile containing a grave to clean, null otherwise + * @param level Level in which searched + * @param moves List of coordinates in which to search + * @param cFrom Original coordinate + * @param player Player starting the search + * @return Coordinate of a tile containing a grave to clean, null otherwise */ - static Coordinate cleanGraves (Playable level, List moves, Coordinate cFrom, Player player) { + static Coordinate cleanGraves(Playable level, List moves, Coordinate cFrom, Player player) { for (Coordinate cTo : moves) { if (!cFrom.equals(cTo)) { @@ -175,14 +171,14 @@ static Coordinate cleanGraves (Playable level, List moves, Coordinat /** * Look for enemy tile to occupy * - * @param level Level in which searched - * @param moves List of coordinates in which to search - * @param cFrom Original coordinate - * @param player Player starting the search - * @return Coordinate of a enemy tile, null otherwise + * @param level Level in which searched + * @param moves List of coordinates in which to search + * @param cFrom Original coordinate + * @param player Player starting the search + * @return Coordinate of a enemy tile, null otherwise */ - static Coordinate attackEnemy (Playable level, List moves, Coordinate cFrom, Player player) { + static Coordinate attackEnemy(Playable level, List moves, Coordinate cFrom, Player player) { for (Coordinate cTo : moves) { if (!cFrom.equals(cTo)) { Tile current = level.get(cTo); @@ -199,14 +195,14 @@ static Coordinate attackEnemy (Playable level, List moves, Coordinat /** * Search for soldier to fusion in the player's territory * - * @param level Level in which searched - * @param moves List of coordinates in which to search - * @param cFrom Original coordinate - * @param player Player starting the search - * @return Coordinate of a tile containing a soldier to fusion, null otherwise + * @param level Level in which searched + * @param moves List of coordinates in which to search + * @param cFrom Original coordinate + * @param player Player starting the search + * @return Coordinate of a tile containing a soldier to fusion, null otherwise */ - static Coordinate fusion (Playable level, List moves, Coordinate cFrom, Player player) { + static Coordinate fusion(Playable level, List moves, Coordinate cFrom, Player player) { for (Coordinate cTo : moves) { if (!cFrom.equals(cTo)) { Tile current = level.get(cTo); @@ -229,12 +225,12 @@ static Coordinate fusion (Playable level, List moves, Coordinate cFr /** * Find the nearest coordinate in the list of the original coordinate * - * @param cFrom Original coordinate - * @param coordinates List in which to look for the nearest coordinate - * @return The nearest coordinate to the original coordinates + * @param cFrom Original coordinate + * @param coordinates List in which to look for the nearest coordinate + * @return The nearest coordinate to the original coordinates */ - private static Coordinate nearestCoordinates (Coordinate cFrom, List coordinates) { + private static Coordinate nearestCoordinates(Coordinate cFrom, List coordinates) { int dstMin = 1000; if (coordinates.size() != 0 && cFrom != null) { Coordinate cMin = coordinates.get(0); @@ -253,14 +249,14 @@ private static Coordinate nearestCoordinates (Coordinate cFrom, List /** * Find the coordinate in the territory of the player closest to enemy territory * - * @param cFrom Original coordinate - * @param level Level in which searched - * @param player Player starting the search - * @param toBuy Boolean to differentiate the case of a purchase (true) from the case of a move (false) - * @return Coordinate found + * @param cFrom Original coordinate + * @param level Level in which searched + * @param player Player starting the search + * @param toBuy Boolean to differentiate the case of a purchase (true) from the case of a move (false) + * @return Coordinate found */ - static Coordinate searchEnnemy (Coordinate cFrom, Playable level, Player player, Soldier toBuy) { + static Coordinate searchEnnemy(Coordinate cFrom, Playable level, Player player, Soldier toBuy) { List> allEnemy = loadTerritories(level, player, true); List listNear = new ArrayList(); diff --git a/core/src/be/ac/umons/slay/g02/players/AIRandom.java b/core/src/be/ac/umons/slay/g02/players/AIRandom.java index 524cdf3..e747624 100644 --- a/core/src/be/ac/umons/slay/g02/players/AIRandom.java +++ b/core/src/be/ac/umons/slay/g02/players/AIRandom.java @@ -6,7 +6,6 @@ import be.ac.umons.slay.g02.entities.Soldier; import be.ac.umons.slay.g02.entities.SoldierLevel; -import be.ac.umons.slay.g02.entities.StaticEntity; import be.ac.umons.slay.g02.gui.screens.GameScreen; import be.ac.umons.slay.g02.level.Coordinate; import be.ac.umons.slay.g02.level.Playable; @@ -21,11 +20,12 @@ public class AIRandom extends Player implements AI { /** * Constructor of the class, initiating its name, its color and the path of its avatar + * * @param color Player color * @param name Player name */ - public AIRandom (Colors color, String name) { + public AIRandom(Colors color, String name) { this.name = name; this.color = color; avatar = "profile" + File.separator + "ai_random.png"; @@ -45,37 +45,37 @@ public boolean play(Player player, boolean forMe) { for (List territory : allTerritories) { - // Ajouter une unité ? + // Buy a unit ? Coordinate cFrom = territory.get(0); Territory terr = level.get(cFrom).getTerritory(); for (int i = 1; i <= 4; i++) { Soldier entity = new Soldier(SoldierLevel.fromLevel(i)); - // Essai ajouter chacun des soldats possibles en commencant par le plus faible + // Try adding each possible soldier by starting with the weakest if (terr.canBuy(entity)) { - // Je peux l'acheter => choix d'une case aléatoire où la placer + // Can buy soldier => choice random tile List moves = level.getMoves(entity, cFrom); int rand = new Random().nextInt(moves.size()); level.buy(entity, cFrom, moves.get(rand)); } } - // Déplacer une unité ? + // Move a unit ? for (Coordinate coordinate : territory) { - // Parcours toutes les cases de ce terroire + // Go through all the boxes of this terroir Tile tile = level.get(coordinate); if (tile.getEntity() != null && tile.getEntity() instanceof Soldier) { - // Si il y a un soldat + // There is a soldier Soldier soldier = (Soldier) tile.getEntity(); if (!soldier.getMoved()) { - // Il ne s'est pas encore déplacé = > choix d'une case aléatoire + // Soldier not already moved = > choice random tile List moves = level.getMoves(coordinate, 4); int rand = new Random().nextInt(moves.size()); level.move(coordinate, moves.get(rand)); - } } } } - // finir son tour + } + // Ends its turn return level.nextTurn(); } } diff --git a/core/src/be/ac/umons/slay/g02/players/Account.java b/core/src/be/ac/umons/slay/g02/players/Account.java index a8db53a..db7a940 100644 --- a/core/src/be/ac/umons/slay/g02/players/Account.java +++ b/core/src/be/ac/umons/slay/g02/players/Account.java @@ -1,7 +1,7 @@ package be.ac.umons.slay.g02.players; /** - * //TODO + * Class containing the username and the password of a logged user */ public class Account { @@ -9,36 +9,36 @@ public class Account { String password; /** - * //TODO + * Gives the username * - * @return + * @return the username */ public String getUsername() { return username; } /** - * //TODO + * Sets a username * - * @param username + * @param username the username */ public void setUsername(String username) { this.username = username; } /** - * //TODO + * Gives the password * - * @return + * @return the password */ public String getPassword() { return password; } /** - * //TODO + * Sets a password * - * @param password + * @param password the password */ public void setPassword(String password) { this.password = password; diff --git a/core/src/be/ac/umons/slay/g02/players/Colors.java b/core/src/be/ac/umons/slay/g02/players/Colors.java index 9ae7bb6..00d20f2 100644 --- a/core/src/be/ac/umons/slay/g02/players/Colors.java +++ b/core/src/be/ac/umons/slay/g02/players/Colors.java @@ -3,7 +3,7 @@ import com.badlogic.gdx.graphics.Color; /** - * TODO + * Enumeration of all colors attributable to a player */ public enum Colors { C1("LIGHT_GREEN", 1), @@ -18,33 +18,33 @@ public enum Colors { private int id; /** - * TODO + * The name and associated number of the color * - * @param name - * @param id + * @param name its name + * @param id its identifier */ - Colors (String name, int id) { + Colors(String name, int id) { this.name = name; this.id = id; } /** - * TODO + * Gives the color's name * - * @return + * @return the color's name */ public String getName() { return this.name; } /** - * TODO + * Gives the color associated with the id * - * @param id - * @return + * @param id the id for which we want the corresponding color + * @return the corresponding color */ public static Colors fromId(int id) { - for (Colors color: Colors.values()) { + for (Colors color : Colors.values()) { if (id == color.id) { return color; } @@ -53,9 +53,9 @@ public static Colors fromId(int id) { } /** - * TODO + * Converts an instance of Colors into an instance of Color (no "s") * - * @return + * @return the corresponding instance of Color */ public Color toColor() { Color color = new Color(); diff --git a/core/src/be/ac/umons/slay/g02/players/DataHashing.java b/core/src/be/ac/umons/slay/g02/players/DataHashing.java index 12d259f..b1b93da 100644 --- a/core/src/be/ac/umons/slay/g02/players/DataHashing.java +++ b/core/src/be/ac/umons/slay/g02/players/DataHashing.java @@ -4,7 +4,7 @@ /** * Class containing the methods to hash user passwords - * + *

* Source: https://dzone.com/articles/storing-passwords-java-web */ public class DataHashing { diff --git a/core/src/be/ac/umons/slay/g02/players/FileBuilder.java b/core/src/be/ac/umons/slay/g02/players/FileBuilder.java index 28db8dc..fb2c069 100644 --- a/core/src/be/ac/umons/slay/g02/players/FileBuilder.java +++ b/core/src/be/ac/umons/slay/g02/players/FileBuilder.java @@ -19,12 +19,11 @@ import javax.xml.transform.stream.StreamResult; import be.ac.umons.slay.g02.gui.Main; -import be.ac.umons.slay.g02.gui.screens.Menu; import static be.ac.umons.slay.g02.gui.Main.tabPlayers; /** - * //TODO + * Class building the xml file containing the data of all players with an account */ public class FileBuilder { Document doc; @@ -32,7 +31,10 @@ public class FileBuilder { private String nameFile = Main.getNameFile(); /** - * //TODO + * Creates the xml file of players data + *

+ * It retrieves all players in tabPlayers in which there is all players with an account, then + * writes all the values they have obtained for each statistic */ public void createFile() { @@ -40,6 +42,7 @@ public void createFile() { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); + // Root of the xml file doc = docBuilder.newDocument(); Element root = doc.createElement("statistics"); @@ -112,7 +115,8 @@ public void createFile() { } /** - * //TODO + * Get the values a player has obtained for the statistics, from the hasmap of statistics in + * the parameter entry, and writes them one by one in the file * * @param doc * @param newElement diff --git a/core/src/be/ac/umons/slay/g02/players/GlobalStats.java b/core/src/be/ac/umons/slay/g02/players/GlobalStats.java index 943df5d..df77cc1 100644 --- a/core/src/be/ac/umons/slay/g02/players/GlobalStats.java +++ b/core/src/be/ac/umons/slay/g02/players/GlobalStats.java @@ -5,43 +5,43 @@ import be.ac.umons.slay.g02.gui.screens.LevelSelection; /** - * //TODO + * Class handling all global statistics plus the rank and score of the player */ public class GlobalStats extends Statistics { private int rank; private int score = 0; /** - * //TODO + * Gives the players'rank in the hall of fame * - * @return + * @return the players'rank */ public int getRank() { return rank; } /** - * //TODO + * Sets the players'rank in the hall of fame * - * @param rank + * @param rank the players'rank */ public void setRank(int rank) { this.rank = rank; } /** - * //TODO + * Gives the players'score in the hall of fame * - * @return + * @return the players'score */ public int getScore() { return score; } /** - * //TODO + * Sets the players'score in the hall of fame * - * @param score + * @param score the players'score */ public void setScore(int score) { this.score = score; @@ -49,7 +49,7 @@ public void setScore(int score) { /** * Updates the values of the statistics in the hashmap stats - * + *

* A global statistic can be : * - a minimum value, i.e. the minimum value of the statistic among all worlds (0 is excluded if * at least one value of the statistic in a world is different of zero @@ -79,14 +79,13 @@ public void updateStats(HumanPlayer player) { } } // If the global statistic to update is a maximum - else if (stat.startsWith(MAX_)) - { + else if (stat.startsWith(MAX_)) { // Searches for the maximum value among all levels for (int i = 1; i <= LevelSelection.TOTAL_NUMBER_ISLANDS; i++) { int levelValue = player.getListLevelStats(i).getStats().get(stat); - globalValue=Math.max(levelValue, globalValue); + globalValue = Math.max(levelValue, globalValue); getStats().put(stat, Math.max(levelValue, globalValue)); } } @@ -96,8 +95,8 @@ All other global statistics are total ones (Games, Wins and Defeats are excluded because they are not used to calculate average statistics, which is why they have been updated elsewhere) */ - else if (stat == GAMES ) - updateTotal(); + else if (stat == GAMES) + updateTotal(); } } } \ No newline at end of file diff --git a/core/src/be/ac/umons/slay/g02/players/HumanPlayer.java b/core/src/be/ac/umons/slay/g02/players/HumanPlayer.java index c422ab9..399a657 100644 --- a/core/src/be/ac/umons/slay/g02/players/HumanPlayer.java +++ b/core/src/be/ac/umons/slay/g02/players/HumanPlayer.java @@ -5,7 +5,7 @@ import java.util.List; /** - * //TODO + * Class assigned to a user with an account */ public class HumanPlayer extends Player { Account account; @@ -13,10 +13,10 @@ public class HumanPlayer extends Player { List listLevelStats = new ArrayList(); /** - * //TODO + * Constructor class which determines the player's attributes * - * @param name - * @param color + * @param name the player's name to display + * @param color the player's color in game */ public HumanPlayer(String name, Colors color) { this.name = name; @@ -24,59 +24,66 @@ public HumanPlayer(String name, Colors color) { } /** - * //TODO + * Gives the list of all instances of LevelStats (there are as many as there are playable + * levels) * - * @return + * @return the list of all instances of LevelStats */ public List getListLevelStats() { return listLevelStats; } /** - * //TODO + * Sets the list of all instances of LevelStats (there are as many as there are playable + * levels) * - * @param listLevelStats + * @param listLevelStats the list of all instances of LevelStats */ public void setListLevelStats(List listLevelStats) { this.listLevelStats = listLevelStats; } + /** + * Gets the player's account + * + * @return the player's account + */ public Account getAccount() { return account; } /** - * //TODO + * Sets the player's account * - * @param account + * @param account the player's account */ public void setAccount(Account account) { this.account = account; } /** - * //TODO + * Gives the instance of GlobalStats assigned to the player * - * @return + * @return the player's instance of GlobalStats */ public GlobalStats getGlobalStats() { return globalStats; } /** - * //TODO + * Sets the instance of GlobalStats assigned to the player * - * @param globalStats + * @param globalStats the player's instance of GlobalStats */ public void setGlobalStats(GlobalStats globalStats) { this.globalStats = globalStats; } /** - * //TODO + * Gives the instance of LevelStats corresponding to the level number in the entry * - * @param level - * @return + * @param level the level number for which we want the instance of LevelStats + * @return the corresponding instance of LevelStats */ public LevelStats getListLevelStats(int level) { Iterator iter = listLevelStats.iterator(); @@ -90,11 +97,6 @@ public LevelStats getListLevelStats(int level) { return null; } - /** - * //TODO - * - * @return - */ @Override public String toString() { return name; diff --git a/core/src/be/ac/umons/slay/g02/players/Player.java b/core/src/be/ac/umons/slay/g02/players/Player.java index 807aab3..6b1b30d 100644 --- a/core/src/be/ac/umons/slay/g02/players/Player.java +++ b/core/src/be/ac/umons/slay/g02/players/Player.java @@ -1,7 +1,7 @@ package be.ac.umons.slay.g02.players; /** - * //TODO + * Class assigned to a player */ public abstract class Player { String name; @@ -9,64 +9,64 @@ public abstract class Player { Colors color; /** - * //TODO + * Gives the color given to the player * - * @return + * @return the player's color */ public Colors getColor() { return color; } /** - * //TODO + * Gives the player's name * - * @return + * @return the player's name */ public String getName() { return name; } /** - * //TODO + * Sets the player's name * - * @param name + * @param name the player's name */ public void setName(String name) { this.name = name; } /** - * //TODO + * Sets the player's color * - * @param color + * @param color the player's color */ public void setColor(Colors color) { this.color = color; } /** - * //TODO + * Gives the player's avatar * - * @return + * @return the player's avatar */ public String getAvatar() { return avatar; } /** - * //TODO + * Sets the player's avatar * - * @param avatar + * @param avatar the player's avatar */ public void setAvatar(String avatar) { this.avatar = avatar; } /** - * //TODO + * Returns if the object to be compared is equal to the player * - * @param o - * @return + * @param o Object to compare + * @return True if they are equal, false otherwise */ @Override public boolean equals(Object o) { diff --git a/core/src/be/ac/umons/slay/g02/players/Statistics.java b/core/src/be/ac/umons/slay/g02/players/Statistics.java index da3409b..71957cb 100644 --- a/core/src/be/ac/umons/slay/g02/players/Statistics.java +++ b/core/src/be/ac/umons/slay/g02/players/Statistics.java @@ -195,7 +195,7 @@ public void updateStats() { } /** - * //TODO + * Calculates the "total" statistics * * @param key */ diff --git a/core/src/be/ac/umons/slay/g02/players/StatsLoader.java b/core/src/be/ac/umons/slay/g02/players/StatsLoader.java index ed4921b..dea5d08 100644 --- a/core/src/be/ac/umons/slay/g02/players/StatsLoader.java +++ b/core/src/be/ac/umons/slay/g02/players/StatsLoader.java @@ -20,13 +20,15 @@ import static be.ac.umons.slay.g02.gui.Main.prefs; /** - * //TODO + * Class that retrieves all data from the xml file containing players data, by creating instances + * of Account, HumanPlayer, GlobalStats and LevelStats and then putting the values in them */ public class StatsLoader { /** - * //TODO + * Creates an instance of HumanPlayer for each player in the file and creates instances of + * Account, HumanPlayer, GlobalStats and LevelStats for each one of them to store their data * - * @return + * @return an instance of ArrayList containing all the instances of HumanPlayer created */ public ArrayList createTab() { ArrayList tabScore = new ArrayList(); @@ -126,10 +128,11 @@ public ArrayList createTab() { } /** - * //TODO + * Retrieves the value read by deleting the numbers before the statistic name (to get the + * good key) then put it in the corresponding hashmap of statistics * - * @param elementStat - * @param hashmapStats + * @param elementStat TODO player's name ? + * @param hashmapStats the hashmap of statistics */ private void putInHashmapStats(Element elementStat, HashMap hashmapStats) { // Deletes the numbers (used for easier reading) before the statistics @@ -137,13 +140,12 @@ private void putInHashmapStats(Element elementStat, HashMap has for (int i = 0; i < stat.length(); i++) { String a = "" + stat.charAt(0); if (!a.equals("_")) - stat = stat.substring(1, stat.length()); + stat = stat.substring(1); else i = stat.length(); } - stat = stat.substring(2, stat.length()); - if (hashmapStats.containsKey(stat)) { + stat = stat.substring(2); + if (hashmapStats.containsKey(stat)) hashmapStats.put(stat, Integer.parseInt(elementStat.getFirstChild().getNodeValue())); - } } } \ No newline at end of file diff --git a/core/src/be/ac/umons/slay/g02/tests/LevelTests.java b/core/src/be/ac/umons/slay/g02/tests/LevelTests.java index 18ede43..51711d3 100644 --- a/core/src/be/ac/umons/slay/g02/tests/LevelTests.java +++ b/core/src/be/ac/umons/slay/g02/tests/LevelTests.java @@ -1,13 +1,8 @@ package be.ac.umons.slay.g02.tests; -import com.badlogic.gdx.Gdx; - import org.junit.BeforeClass; import org.junit.Test; - -import com.badlogic.gdx.Application; - import java.io.File; import java.util.ArrayList; @@ -16,9 +11,7 @@ import be.ac.umons.slay.g02.entities.StaticEntity; import be.ac.umons.slay.g02.gui.Main; import be.ac.umons.slay.g02.level.Coordinate; -import be.ac.umons.slay.g02.level.FileFormatException; import be.ac.umons.slay.g02.level.Level; -import be.ac.umons.slay.g02.level.LevelLoader; import be.ac.umons.slay.g02.level.Playable; import be.ac.umons.slay.g02.level.Territory; import be.ac.umons.slay.g02.level.Tile; @@ -29,10 +22,10 @@ import be.ac.umons.slay.g02.players.Statistics; import be.ac.umons.slay.g02.players.StatsLoader; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** - * Class testing ... TODO + * Class testing Level */ public class LevelTests { static ArrayList tabPlayers; @@ -45,9 +38,8 @@ public class LevelTests { static HumanPlayer player; /** - * Creates a player, a level and a soldier, then merges two units of player + * Creates a player, a level and a soldier, then merges two units of player */ - /* @BeforeClass public static void setUp() { Main.isInTest = true; @@ -73,13 +65,8 @@ public static void setUp() { // Simulates the merge of two L0 belonging to player, it creates one L1 level.updatePlayerStatsMerge(player, 0, 0, 1); - }*/ + } - /** - * //TODO - * - * @return - */ private static Playable loadLvl() { Playable level = new Level(5, 5); Player p1 = new HumanPlayer("P1", Colors.C1); @@ -131,9 +118,9 @@ private static Playable loadLvl() { level.set(t33, c33); Tile water = new Tile(TileType.WATER); - for(int i = 0; i < level.width(); i++) { - for(int j = 0; j < level.height(); j++) { - if (i == 0 || i == level.width() - 1 || j == 0 || j == level.height()-1) + for (int i = 0; i < level.width(); i++) { + for (int j = 0; j < level.height(); j++) { + if (i == 0 || i == level.width() - 1 || j == 0 || j == level.height() - 1) level.set(water, new Coordinate(i, j)); } } @@ -154,9 +141,6 @@ private static Playable loadLvl() { return level; } - /** - * //TODO - */ @Test public void mergeSoldier() { Coordinate c0 = new Coordinate(2, 1); @@ -164,7 +148,7 @@ public void mergeSoldier() { Playable level = loadLvl(); level.nextTurn(); level.move(c0, c1); - assertEquals("L1",level.get(c1).getEntity().getName()); + assertEquals("L1", level.get(c1).getEntity().getName()); } @Test @@ -177,7 +161,7 @@ public void chopTree() { level.move(c0, c1); int after = level.get(c0).getTerritory().getCoins(); - assertEquals(before,after); + assertEquals(before, after); } @Test @@ -186,12 +170,9 @@ public void cantAttack() { Coordinate c0 = new Coordinate(2, 1); Coordinate c1 = new Coordinate(2, 2); - assertEquals(false,level.canMove(c0, c1)); + assertEquals(false, level.canMove(c0, c1)); } - /** - * //TODO - */ @Test public void attackSoldier() { Playable level = loadLvl(); @@ -200,7 +181,7 @@ public void attackSoldier() { Coordinate c1 = new Coordinate(2, 1); level.move(c0, c1); - assertEquals("L1",level.get(c1).getEntity().getName()); + assertEquals("L1", level.get(c1).getEntity().getName()); } @Test @@ -215,7 +196,7 @@ public void conquerEnemyTerritory() { level.move(c0, c1); //TODO Comportement bizarre après le split dans move - assertEquals("P2",level.get(c1).getTerritory().getOwner().getName()); + assertEquals("P2", level.get(c1).getTerritory().getOwner().getName()); } @Test @@ -235,15 +216,12 @@ public void conquerNeutralTerritory() { Coordinate c0 = new Coordinate(2, 2); Coordinate c1 = new Coordinate(1, 2); level.move(c0, c1); - assertEquals("P1",level.get(c1).getTerritory().getOwner().getName()); + assertEquals("P1", level.get(c1).getTerritory().getOwner().getName()); } - - - /** - * Tests if the counter currentLostL. (for global statistics) is correctly updated + * Tests if the counter currentLostL. (for global statistics) is correctly updated */ @Test public void testUpdatePlayerStatsLostGlobal() { @@ -259,7 +237,7 @@ public void testUpdatePlayerStatsLostGlobal() { } /** - * Tests if the counter currentLostL. (for statistics of a specific level) is correctly updated + * Tests if the counter currentLostL. (for statistics of a specific level) is correctly updated */ @Test public void testUpdatePlayerStatsLostLevel() { @@ -275,8 +253,8 @@ public void testUpdatePlayerStatsLostLevel() { } /** - * Checks that the two L0 are removed, i.e. the counter of L0 is subtracted from two (in - * global statistics) + * Checks that the two L0 are removed, i.e. the counter of L0 is subtracted from two (in + * global statistics) */ @Test public void testUpdatePlayerStatsMergeGlobalOld() { @@ -285,8 +263,8 @@ public void testUpdatePlayerStatsMergeGlobalOld() { } /** - * Checks that the L1 is added, i.e. the counter of L1 is increased by one (in global - * statistics) + * Checks that the L1 is added, i.e. the counter of L1 is increased by one (in global + * statistics) */ @Test public void testUpdatePlayerStatsMergeGlobalNew() { @@ -295,8 +273,8 @@ public void testUpdatePlayerStatsMergeGlobalNew() { } /** - * Checks that the two L0 are removed, i.e. the counter of L0 is subtracted from two (in - * statistics of the level) + * Checks that the two L0 are removed, i.e. the counter of L0 is subtracted from two (in + * statistics of the level) */ @Test public void testUpdatePlayerStatsMergeLevelOld() { @@ -305,8 +283,8 @@ public void testUpdatePlayerStatsMergeLevelOld() { } /** - * Checks that the L1 is added, i.e. the counter of L1 is increased by one (in statistics of - * the level) + * Checks that the L1 is added, i.e. the counter of L1 is increased by one (in statistics of + * the level) */ @Test public void testUpdatePlayerStatsMergeLevelNew() { diff --git a/core/src/be/ac/umons/slay/g02/tests/SoldierTests.java b/core/src/be/ac/umons/slay/g02/tests/SoldierTests.java index bbcebf6..2dbf77d 100644 --- a/core/src/be/ac/umons/slay/g02/tests/SoldierTests.java +++ b/core/src/be/ac/umons/slay/g02/tests/SoldierTests.java @@ -8,24 +8,18 @@ import static org.junit.Assert.assertEquals; /** - * TODO + * Class testing Soldier */ public class SoldierTests { - /** - * TODO - */ @Test - public void cantAttackTest () { + public void cantAttackTest() { Soldier s1 = new Soldier(SoldierLevel.L0); Soldier s2 = new Soldier(SoldierLevel.L1); assertEquals(s1.canAttack(s2), false); } - /** - * TODO - */ @Test - public void canAttackTest () { + public void canAttackTest() { Soldier s1 = new Soldier(SoldierLevel.L0); Soldier s2 = new Soldier(SoldierLevel.L1); assertEquals(s2.canAttack(s1), true); diff --git a/core/src/be/ac/umons/slay/g02/tests/StatsLoaderTests.java b/core/src/be/ac/umons/slay/g02/tests/StatsLoaderTests.java new file mode 100644 index 0000000..c6f832c --- /dev/null +++ b/core/src/be/ac/umons/slay/g02/tests/StatsLoaderTests.java @@ -0,0 +1,469 @@ +package be.ac.umons.slay.g02.tests; + +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import be.ac.umons.slay.g02.gui.Main; +import be.ac.umons.slay.g02.players.HumanPlayer; +import be.ac.umons.slay.g02.players.Statistics; +import be.ac.umons.slay.g02.players.StatsLoader; + +import static org.junit.Assert.assertEquals; + +/** + * Class testing StatsLoader, i.e. it tests if players data that are in a xml file are + * correctly retrieved by testing if the recovered value is equal to the stored value + * + * Tests are for global and levels statistics + */ +public class StatsLoaderTests { + static ArrayList tabPlayers; + static Element root; + static Element element; + static HumanPlayer player; + + static boolean isFound; + static int i; + + /** + * Creates a player then goes to the first value to read + * The file used has been specifically made for testing + */ + @BeforeClass + public static void setUp() { + Main.setNameFile("PlayerDataTest.xml"); + Main.isInTest = true; + + // Creates a player + StatsLoader statsLoader = new StatsLoader(); + tabPlayers = statsLoader.createTab(); + player = (HumanPlayer) tabPlayers.get(0); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + File fileStats = new File(Main.getNameFile()); + if (fileStats.exists() && fileStats.length() != 0) { + try { + final DocumentBuilder builder = factory.newDocumentBuilder(); + final Document document = builder.parse(new File(Main.getNameFile())); + root = document.getDocumentElement(); + + for (int i = 0; i < root.getChildNodes().getLength(); i++) { + + Node n = root.getChildNodes().item(i); + + if (n.getNodeName().equals("player")) + element = (Element) n; + } + } catch (final ParserConfigurationException e) { + e.printStackTrace(); + } catch (final SAXException e) { + e.printStackTrace(); + } catch (final IOException e) { + e.printStackTrace(); + } + } + } + + @After + public void tearDown() { + isFound = false; + i = 0; + } + + @Test + public void testName() { + String name = ""; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("name")) { + name = elem.getFirstChild().getNodeValue(); + isFound = true; + } + i++; + } + assertEquals(player.getName(), name); + } + + @Test + public void testPassword() { + String password = ""; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("password")) { + password = elem.getFirstChild().getNodeValue(); + isFound = true; + } + i++; + } + assertEquals(player.getAccount().getPassword(), password); + } + + @Test + public void testAvatar() { + String avatar = ""; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("avatar")) { + avatar = elem.getFirstChild().getNodeValue(); + isFound = true; + } + i++; + } + assertEquals(player.getAvatar(), avatar); + } + + @Test + public void testScore() { + int score = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("score")) { + score = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals(player.getGlobalStats().getScore(), score); + } + + @Test + public void testGameG() { + int game = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__1__Games")) { + game = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.GAMES), game); + } + + @Test + public void testGameL() { + int game = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__1__Games")) { + game = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.GAMES), game); + } + + @Test + public void testWinsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__2__Wins")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.WINS), value); + } + + @Test + public void testWinsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__2__Wins")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.WINS), value); + } + + @Test + public void testDefeatsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__3__Defeats")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.DEFEATS), value); + } + + @Test + public void testDefeatsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__3__Defeats")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.DEFEATS), value); + } + + @Test + public void testMinTurnsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__4__min_Turns")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.MIN_TURNS), value); + } + + @Test + public void testMinTurnsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__4__min_Turns")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.MIN_TURNS), value); + } + + @Test + public void testTurnsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__5__Turns")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.TURNS), value); + } + + @Test + public void testTurnsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__5__Turns")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.TURNS), value); + } + + @Test + public void testMaxLandsTurnsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__6__max_Lands_Turn")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.MAX_LANDS_TURN), value); + } + + @Test + public void testMaxLandsTurnsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__6__max_Lands_Turn")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.MAX_LANDS_TURN), value); + } + + @Test + public void testLandsTurnsG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__7__Lands_Turn")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.LANDS_TURN), value); + } + + @Test + public void testLandsTurnsL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__7__Lands_Turn")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.LANDS_TURN), value); + } + + @Test + public void testMaxTreesG() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("__8__max_Trees")) { + value = Integer.parseInt(elem.getFirstChild().getNodeValue()); + isFound = true; + } + i++; + } + assertEquals((int) player.getGlobalStats().getStats().get(Statistics.MAX_TREES), value); + } + + @Test + public void testMaxTreesL() { + int value = 0; + Element elem; + + while (i < element.getChildNodes().getLength() && !isFound) { + + elem = (Element) element.getChildNodes().item(i); + if (elem.getNodeName().equals("levelStats")) { + int k = 0; + while (k < elem.getChildNodes().getLength() && !isFound) { + Element e = (Element) elem.getChildNodes().item(k); + if (e.getNodeName().equals("__8__max_Trees")) { + value = Integer.parseInt(e.getFirstChild().getNodeValue()); + isFound = true; + } + k++; + } + } + i++; + } + assertEquals((int) player.getListLevelStats(1).getStats().get(Statistics.MAX_TREES), value); + } +} \ No newline at end of file