From a93ab4954dd02bb9b5d0eeef0877c89c64b832f5 Mon Sep 17 00:00:00 2001 From: cemal Date: Wed, 1 Jun 2022 23:27:23 +0200 Subject: [PATCH] Added buy action button but not yet implemented in jFX --- .../application/LaticeApplicationConsole.java | 9 ++ .../application/LaticeApplicationWindow.java | 138 ++++++++++++------ src/main/java/latice/model/Constant.java | 21 +++ src/test/java/latice/LaticeTest.java | 8 +- 4 files changed, 131 insertions(+), 45 deletions(-) create mode 100644 src/main/java/latice/model/Constant.java diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index f1f688b..0066200 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -167,6 +167,15 @@ public class LaticeApplicationConsole { case 2: + if (player.getScore()>=3) { + //Donner une action supplémentaire et enlever 3 points au joueur + player.Play(play, board, 0); + player.diffScore(3); + }else { + System.out.println("Il vous faut 3 points pour acheter une nouvelle action !"); + } + + case 3: player.getRack().changeRack(); System.out.println("Votre rack à été changé avec succès !"); diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 6258652..516d2a9 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -39,6 +39,7 @@ import javafx.stage.Stage; import latice.controller.MainScreenController; import latice.controller.PlayerNameInputController; import latice.model.Color; +import latice.model.Constant; import latice.model.Player; import latice.model.Shape; import latice.model.Tile; @@ -49,18 +50,6 @@ import latice.model.window.RectangleFX; public class LaticeApplicationWindow extends Application { - private static final int NUMBER_OF_BOX_ON_ONE_LINE = 9; - - private static final int RECTANGLE_HEIGHT = 50; - - private static final int RECTANGLE_WIDTH = 50; - - private static final int Y_CENTER = 37; - - private static final int X_CENTER = 355; - - private static final int BOX_WIDTH = 52; - javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0); Image image = new Image("backgroundLatice.png"); @@ -132,10 +121,10 @@ public class LaticeApplicationWindow extends Application { Rectangle[][] r = new Rectangle[9][9]; int counterI = 0; int counterJ = 0; - for (int i=1; i<=NUMBER_OF_BOX_ON_ONE_LINE ; i++) { - for (int j=1; j <= NUMBER_OF_BOX_ON_ONE_LINE ; j++) { + for (int i=1; i<=Constant.NUMBER_OF_BOX_ON_ONE_LINE ; i++) { + for (int j=1; j <= Constant.NUMBER_OF_BOX_ON_ONE_LINE ; j++) { - r[counterI][counterJ] = new Rectangle(i*BOX_WIDTH+X_CENTER,j*BOX_WIDTH+Y_CENTER,RECTANGLE_WIDTH,RECTANGLE_HEIGHT); + r[counterI][counterJ] = new Rectangle(i*Constant.BOX_WIDTH+Constant.X_CENTER,j*Constant.BOX_WIDTH+Constant.Y_CENTER,Constant.RECTANGLE_WIDTH,Constant.RECTANGLE_HEIGHT); r[counterI][counterJ].setFill(realColor.TRANSPARENT); pane.getChildren().add(r[counterI][counterJ]); System.out.println(r[counterI][counterJ]); @@ -206,23 +195,25 @@ public class LaticeApplicationWindow extends Application { //Confirm Button - Image checkMark = new Image("checkMark.png"); - ImageView checkMarkView = new ImageView(checkMark); - Button confirmButton = new Button("Confirm", checkMarkView); - - confirmButton.setOnMouseClicked(new EventHandler() { + Image checkMark = new Image("checkMark.png"); + ImageView checkMarkView = new ImageView(checkMark); + Button confirmButton = new Button("Confirm", checkMarkView); + confirmButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); + confirmButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); + + confirmButton.setOnMouseClicked(new EventHandler() { - @Override - public void handle(MouseEvent arg0) { - - - System.out.println("confirmed placement"); - - validateBtnClickedCount++; - - } - - }); + @Override + public void handle(MouseEvent arg0) { + + + System.out.println("confirmed placement"); + + validateBtnClickedCount++; + + } + + }); //With Image @@ -234,7 +225,15 @@ public class LaticeApplicationWindow extends Application { Image changeIconImage = new Image("changeIcon.png"); ImageView changeIconView = new ImageView(changeIconImage); Button changeButton = new Button("Change Rack", changeIconView); + changeButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); + changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); + //Buy another action Button + Image buyActionImage = new Image("buyAction.png"); + ImageView buyActionView = new ImageView(buyActionImage); + Button buyActionButton = new Button("Buy Action", buyActionView); + buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); + buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); changeButton.setOnMouseClicked(new EventHandler() { @@ -247,14 +246,30 @@ public class LaticeApplicationWindow extends Application { rackImage.getChildren().clear(); - rackImage.getChildren().addAll(rack2.createTileImage(), confirmButton, changeButton); + rackImage.getChildren().addAll(rack2.createTileImage(), confirmButton, changeButton, buyActionButton); //Setting drag n drop on tiles setDragnDropOnRack(rackImage); } }); - rackImage.getChildren().addAll(confirmButton, changeButton); + + buyActionButton.setOnMouseClicked(new EventHandler() { + + @Override + public void handle(MouseEvent arg0) { + //TODO verify score and give another play() + /*if (player.getScore()>=3) { + //Donner une action supplémentaire et enlever 3 points au joueur + player.Play(play, board, 0); + player.diffScore(3); + }else { + System.out.println("Il vous faut 3 points pour acheter une nouvelle action !"); + }*/ + } + + }); + rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); root.setBottom(rackImage); //Adding lists to Arraylists @@ -274,12 +289,33 @@ public class LaticeApplicationWindow extends Application { //------------------------------------------------------------------------ //###################### creating all rectangles and DragnDrop ######################// - RectangleFX rectFX = new RectangleFX(); - rectFX.createRectangle(root, pane); - rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); - rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); + //ectangleFX rectFX = new RectangleFX(); + //rectFX.createRectangle(root, pane); + //rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); + //rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); //------------------------------------------------------------------------ + //Setting drag & drop on rectangles + for(int i=0; i() { + + @Override + public void handle(DragEvent arg0) { + if (arg0.getDragboard().hasString()){ + Dragboard dragboard = arg0.getDragboard(); + + r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked()))); + } + arg0.consume(); + } + }); + + r[a][b].setOnDragExited(new EventHandler() { + @Override public void handle(DragEvent arg0) { if (arg0.isDropCompleted() == false) { @@ -315,8 +351,8 @@ public class LaticeApplicationWindow extends Application { }else { moonErrorLabel.setText("Error ! Please place the first tile on the moon"); //removing all tiles from gameboard - for(int i=0; i allPlayers = new ArrayList<>(); + allPlayers.add(player1); + allPlayers.add(player2); + + for (Player nameplayer : allPlayers ) { + VBox player = new VBox(); + Text name = new Text(); name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20)); name.setText(nameplayer.getName()); @@ -349,7 +404,7 @@ public class LaticeApplicationWindow extends Application { players.setMargin(player, new Insets(50,0,0,55)); } System.out.println("largeur : " + root.getMaxWidth()); - players.setSpacing(850); + players.setSpacing(850); @@ -377,6 +432,7 @@ public class LaticeApplicationWindow extends Application { //Setting drag n drop on tiles for (int i=0; i<5; i++) { int a = i; + System.out.println(a); rackImage.getChildren().get(a).setOnDragDetected(new EventHandler() { @Override @@ -449,4 +505,4 @@ public class LaticeApplicationWindow extends Application { root.setRight(player2); } -} +} \ No newline at end of file diff --git a/src/main/java/latice/model/Constant.java b/src/main/java/latice/model/Constant.java new file mode 100644 index 0000000..1478d85 --- /dev/null +++ b/src/main/java/latice/model/Constant.java @@ -0,0 +1,21 @@ +package latice.model; + +public class Constant { + //for creating rectangles + public static final int NUMBER_OF_BOX_ON_ONE_LINE = 9; + + public static final int RECTANGLE_HEIGHT = 50; + + public static final int RECTANGLE_WIDTH = 50; + + public static final int Y_CENTER = 37; + + public static final int X_CENTER = 355; + + public static final int BOX_WIDTH = 52; + + public static final int ACTION_BUTTONS_WIDTH = 120; + + public static final int ACTION_BUTTONS_HEIGHT = 45; + +} diff --git a/src/test/java/latice/LaticeTest.java b/src/test/java/latice/LaticeTest.java index 6613aff..379c4f9 100644 --- a/src/test/java/latice/LaticeTest.java +++ b/src/test/java/latice/LaticeTest.java @@ -1,20 +1,20 @@ package latice; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; import latice.model.Color; -import latice.model.Deck; import latice.model.Player; import latice.model.Position; -import latice.model.Rack; -import latice.model.Score; import latice.model.Shape; import latice.model.Tile; +import latice.model.console.Deck; +import latice.model.console.Rack; +import latice.model.console.Score; class LaticeTest {