From afe085a20e14b52ee7ff43bdd060c5d13846b127 Mon Sep 17 00:00:00 2001 From: Mathis Date: Fri, 3 Jun 2022 21:10:30 +0200 Subject: [PATCH] UPDATE Constant, PlayerFX, Rack, Rules --- src/main/java/latice/model/Constant.java | 7 ++- src/main/java/latice/model/Rules.java | 24 +++++---- src/main/java/latice/model/console/Rack.java | 4 +- .../java/latice/model/window/PlayerFX.java | 54 +++++++++++-------- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/main/java/latice/model/Constant.java b/src/main/java/latice/model/Constant.java index 71cd688..cb4bcea 100644 --- a/src/main/java/latice/model/Constant.java +++ b/src/main/java/latice/model/Constant.java @@ -1,7 +1,7 @@ package latice.model; public class Constant { - // + //for the start of the game public static Boolean START = true; //for creating rectangles @@ -11,7 +11,7 @@ public class Constant { public static final int RECTANGLE_WIDTH = 50; - public static final int Y_CENTER = 37; + public static final int Y_CENTER = 6; public static final int X_CENTER = 355; @@ -23,5 +23,8 @@ public class Constant { //Color public static javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0); + + //Dimension width and height of the Latice plateau + public static final int DIMENSION = 9; } diff --git a/src/main/java/latice/model/Rules.java b/src/main/java/latice/model/Rules.java index 450eafb..8569207 100644 --- a/src/main/java/latice/model/Rules.java +++ b/src/main/java/latice/model/Rules.java @@ -26,32 +26,35 @@ public class Rules { public Integer neighborRule(GameBoard board, Tile tile) { Integer nbrNeighbor = 0; - String checkNeighbor = null; + Tile checkNeighbor = null; Boolean checkCase = false; + Boolean badNeighbor = false; for(int i = 0; i < 2 ; i++) { for(int j = -1; j < 2 ; j=j+2) { if (i == 0) { - if (tile.getPositionColumn()+j >= 0 && tile.getPositionColumn()+j <= 9) { - checkNeighbor = board.getGridBoard()[tile.getPositionRow()][tile.getPositionColumn()+j]; + if (tile.getPositionRow() >= 0 && tile.getPositionColumn()+j <= 9) { + checkNeighbor = board.getGridBoardTile()[tile.getPositionRow()][tile.getPositionColumn()+j]; + checkCase = true; } }else { - if (tile.getPositionRow()+j >= 0 && tile.getPositionRow()+j <= 9) { - checkNeighbor = board.getGridBoard()[tile.getPositionRow()+j][tile.getPositionColumn()]; + if (tile.getPositionRow()+j >= 0 && tile.getPositionColumn() <= 9) { + checkNeighbor = board.getGridBoardTile()[tile.getPositionRow()+j][tile.getPositionColumn()]; checkCase = true; } } if (checkCase) { - if (!(GameBoard.SUN.equals(checkNeighbor)) || !(GameBoard.BLUE.equals(checkNeighbor))) { + if ( checkNeighbor != null) { System.out.println("Il y a une tuile"); - if ( tile.getShapeConsole().equals(checkNeighbor.substring(1, 2)) || tile.getColorConsole().equals(checkNeighbor.substring(2, 3)) ) { + if ( tile.getShape() == checkNeighbor.getShape() || tile.getColor() == checkNeighbor.getColor() ) { System.out.println("Il y a correspondance avec la tuile !"); nbrNeighbor = nbrNeighbor + 1; }else { + badNeighbor = true; System.out.println("Il n'y a pas correspondance avec la tuile !"); } @@ -60,8 +63,11 @@ public class Rules { } } - - return nbrNeighbor; + if (badNeighbor) { + return 0; + }else { + return nbrNeighbor; + } } public Boolean sunRule(GameBoard board, Tile tile) { diff --git a/src/main/java/latice/model/console/Rack.java b/src/main/java/latice/model/console/Rack.java index a8b145f..0815b79 100644 --- a/src/main/java/latice/model/console/Rack.java +++ b/src/main/java/latice/model/console/Rack.java @@ -134,13 +134,15 @@ public class Rack { int index; HBox rack = new HBox(); + rackTileImage.clear(); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < this.getListRackTile().size(); i++) { index = i; tile = (this.getListRackTile()).get(index); image = new Image(tile.getShape().getStringShape() + "_" + tile.getColor().getStringColor()+ ".png"); + rackTileImage.add(image); imageView = new ImageView(image); imageView.setFitHeight(80); diff --git a/src/main/java/latice/model/window/PlayerFX.java b/src/main/java/latice/model/window/PlayerFX.java index a8fe9a5..c536280 100644 --- a/src/main/java/latice/model/window/PlayerFX.java +++ b/src/main/java/latice/model/window/PlayerFX.java @@ -6,44 +6,54 @@ import javafx.geometry.Insets; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import latice.model.Player; public class PlayerFX { - + private Text name; + private Text score; + private Text nbrOfTiles; + private VBox infoPlayer; - public static HBox displayPlayers(StackPane root, Player player1, Player player2) { + public VBox displayPlayers(StackPane root, Player player) { //###################### display name, score and deck of each player ######################// - HBox players = new HBox(); + //HBox players = new HBox(); - ArrayList allPlayers = new ArrayList<>(); - allPlayers.add(player1); - allPlayers.add(player2); + //ArrayList allPlayers = new ArrayList<>(); + //allPlayers.add(player1); + //allPlayers.add(player2); - for (Player namePlayer : allPlayers ) { - VBox player = new VBox(); + //for (Player namePlayer : allPlayers ) { + infoPlayer = new VBox(); - Text name = new Text(); - name.setFont(Font.font(namePlayer.getName(), FontWeight.BOLD, 20)); - name.setText(namePlayer.getName()); + name = new Text(); + name.setFont(Font.font(player.getName(), FontWeight.BOLD, 20)); + name.setText(player.getName()); - Text score = new Text(); - score.setText("Score : " + namePlayer.getScore()); + score = new Text(); + score.setText("Score : " + player.getScore()); - Text nbrOfTiles = new Text(); - nbrOfTiles.setText("Tuiles restantes : " + namePlayer.getNumberOfTilesRemaining()); + nbrOfTiles = new Text(); + nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining()); - player.getChildren().addAll(name, score, nbrOfTiles); - player.setSpacing(5); + infoPlayer.getChildren().addAll(name, score, nbrOfTiles); + infoPlayer.setSpacing(5); - players.getChildren().add(player); - players.setMargin(player, new Insets(50,0,0,55)); - } + //players.getChildren().add(infoPlayer); + //players.setMargin(infoPlayer, new Insets(50,0,0,55)); + //} - players.setSpacing(850); - return players; + //players.setSpacing(850); + return infoPlayer; } + public void setFillName(javafx.scene.paint.Color color) { + name.setFill(color); + } + + + }