diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index 73086e0..bf0f1ad 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -110,7 +110,7 @@ public class LaticeApplicationConsole { if (player.getScore()>=3) { //Buy another action and remove 2 points from score player.Play(play, board, 0); - player.diffScore(2); + player.removePointsFromScore(2); }else { System.out.println("Il vous faut 2 points pour acheter une nouvelle action !"); } diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index a7efd71..02f79f1 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -63,7 +63,7 @@ public class LaticeApplicationWindow extends Application { //lists for tiles ArrayList listRackTile; - ArrayList listRackImage; + ArrayList listOfTilesInRack; ArrayList listOfTile = new ArrayList(); static StackPane rootLayout; @@ -92,7 +92,7 @@ public class LaticeApplicationWindow extends Application { Paint tileOnRect; //tile is free when it's the first tile put but tile is payable after - Boolean freeOrPayableTile = true; + Boolean isFreePlacement = true; public static BorderPane borderPane = new BorderPane(); @@ -102,9 +102,9 @@ public class LaticeApplicationWindow extends Application { Stage primaryStageCopy; StackPane parentStackPane = new StackPane(); - Label ErrorLabel = new Label(); + Label gameInfoLabel = new Label(); - HBox rackImage; + HBox rackTileImage; static Label nameWinner = new Label(); int confirmBtnClickedCount; @@ -152,7 +152,7 @@ public class LaticeApplicationWindow extends Application { stage.setScene(menu); parentStackPane.getChildren().remove(root); - //parentStackPane.getChildren().add(root); + parentStackPane.getChildren().add(root); parentStackPane.getChildren().remove(menuBorderPane); }else { @@ -186,9 +186,9 @@ public class LaticeApplicationWindow extends Application { topVbox.setAlignment(Pos.CENTER); //error label for displaying errors - ErrorLabel.setFont(new Font(20)); - ErrorLabel.setTextFill(Constant.realColor.RED); - topVbox.getChildren().add(ErrorLabel); + gameInfoLabel.setFont(new Font(20)); + gameInfoLabel.setTextFill(Constant.realColor.RED); + topVbox.getChildren().add(gameInfoLabel); borderPane.setTop(topVbox); //background image @@ -294,14 +294,14 @@ public class LaticeApplicationWindow extends Application { //RackChange Button Image changeIconImage = new Image("changeIcon.png"); ImageView changeIconView = new ImageView(changeIconImage); - changeButton = new Button("Change Rack", changeIconView); + changeButton = new Button("Change Rack (2 points)", 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); - buyActionButton = new Button("Buy Action", buyActionView); + buyActionButton = new Button("Buy Action (2 points)", buyActionView); buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); @@ -339,13 +339,13 @@ public class LaticeApplicationWindow extends Application { playerFX.setFillName(Constant.realColor.RED); } - freeOrPayableTile = true; + isFreePlacement = true; - rackImage = player.getRack().createTileImage(); - setDragnDropOnRack(rackImage, player); + rackTileImage = player.getRack().createTileImage(); + setDragnDropOnRack(rackTileImage, player); setDragnDropOnRectangles(rect, board, referee, player); - rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); - borderPane.setBottom(rackImage); + rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); + borderPane.setBottom(rackTileImage); } @@ -354,7 +354,7 @@ public class LaticeApplicationWindow extends Application { //switching to game finished screen if the game finishes System.out.println("confirmBtnClickedCount : " + confirmBtnClickedCount); - if (confirmBtnClickedCount>=2) { + if (confirmBtnClickedCount>=20) { Parent loader = FXMLLoader.load(getClass().getResource("../view/GameFinishedScreen.fxml")); Scene gameFinishedScreenScene = new Scene(loader, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT); if (player1.getNumberOfTilesRemaining() < player2.getNumberOfTilesRemaining()) { @@ -379,13 +379,13 @@ public class LaticeApplicationWindow extends Application { }); //With Image - rackImage = player.getRack().createTileImage(); + rackTileImage = player.getRack().createTileImage(); //Adding lists to Arraylists listRackTile = player.getRack().getListRackTile(); System.out.println(listRackTile); - listRackImage = player.getRack().getRackTileImage(); - System.out.println("listTileImge : " + listRackImage); + listOfTilesInRack = player.getRack().getRackTileImage(); + System.out.println("listTileImge : " + listOfTilesInRack); changeButton.setOnMouseClicked(new EventHandler() { @@ -415,18 +415,19 @@ public class LaticeApplicationWindow extends Application { ////// for the next player ////// - freeOrPayableTile = true; - rackImage = player.getRack().createTileImage(); + isFreePlacement = true; + rackTileImage = player.getRack().createTileImage(); //Setting drag n drop on tiles - setDragnDropOnRack(rackImage, player); + setDragnDropOnRack(rackTileImage, player); - rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); + rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); setDragnDropOnRectangles(rect, board, referee, player); - borderPane.setBottom(rackImage); + borderPane.setBottom(rackTileImage); }else { System.out.println("Not enough points to change the rack"); + gameInfoLabel.setText("Error !" + player.getName() + ", you haven't enough points to change your rack"); } } @@ -437,22 +438,15 @@ public class LaticeApplicationWindow extends Application { @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 !"); - }*/ + gameInfoLabel.setText(player.getName() + ", you can now play another time !"); } }); - rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); - setDragnDropOnRack(rackImage, player); + rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); + setDragnDropOnRack(rackTileImage, player); System.out.println(); - borderPane.setBottom(rackImage); + borderPane.setBottom(rackTileImage); //------------------------------------------------------------------------ @@ -460,7 +454,7 @@ public class LaticeApplicationWindow extends Application { System.out.println((indexTileClicked)); - ImagePattern imagePattern = new ImagePattern(listRackImage.get(getIndexTileClicked())); + ImagePattern imagePattern = new ImagePattern(listOfTilesInRack.get(getIndexTileClicked())); //------------------------------------------------------------------------ @@ -471,7 +465,7 @@ public class LaticeApplicationWindow extends Application { - //------if there is already childrens, remove them all to start or restart game------------------------------------------------------------ + //------if there is already childrens, remove them all to start or restart game-------------------------------- root.getChildren().clear(); //adding new childrens root.getChildren().addAll(infoPlayers, borderPane); @@ -490,27 +484,24 @@ public class LaticeApplicationWindow extends Application { rect[a][b].setOnDragEntered(new EventHandler() { - + + //if we are entering a rectangle @Override public void handle(DragEvent arg0) { tileOnRect = rect[a][b].getFill(); - if (arg0.getDragboard().hasString()){ - Dragboard dragboard = arg0.getDragboard(); - - //not putting the virtual image drag on the case because an image is already into it - player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b)); - if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == true ) { - rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked))); - } + //not putting the virtual image drag on the case because an image is already into it + player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b)); + if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == true ) { + rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked))); } arg0.consume(); } }); rect[a][b].setOnDragExited(new EventHandler() { - + //if we are leaving a rectangle @Override public void handle(DragEvent arg0) { if (arg0.isDropCompleted() == false) { @@ -523,6 +514,8 @@ public class LaticeApplicationWindow extends Application { }); rect[a][b].setOnDragOver(new EventHandler () { + + //If we are traveling over a rectangle @Override public void handle(DragEvent arg0) { @@ -532,26 +525,24 @@ public class LaticeApplicationWindow extends Application { }); rect[a][b].setOnDragDropped(new EventHandler() { + + //If we are dropping a tile in a rectangle @Override public void handle(DragEvent arg0) { - System.out.println("entered"); - Dragboard dragboard = arg0.getDragboard(); - System.out.println("OK2"); - rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked))); - arg0.setDropCompleted(true); - System.out.println("OK"); - ErrorLabel.setText(""); + gameInfoLabel.setText(""); - if (referee.checkScoreToPlay(player, freeOrPayableTile) == false) { - ErrorLabel.setText("Error ! You haven't enough points to play another tile"); + //testing if player has enough points + if (referee.checkScoreToPlay(player, isFreePlacement) == false) { + gameInfoLabel.setText("Error !" + player.getName() + ", you haven't enough points to play another tile"); rect[a][b].setFill(tileOnRect); }else { + //testing if it's the free round if (Constant.START) { if (rect[a][b] == rect[Constant.MOON_BOX_X][Constant.MOON_BOX_Y]) { //if its's the center box (moon box) @@ -559,11 +550,11 @@ public class LaticeApplicationWindow extends Application { board.setGridBoardTile(player.getRack().getListRackTile().get(indexTileClicked), a, b); tileDropped = true; - freeOrPayableTile = false; + isFreePlacement = false; Constant.START = false; }else { - ErrorLabel.setText("Error ! Please place the first tile on the moon"); + gameInfoLabel.setText("Error ! " + player.getName() + ", please place the first tile on the moon"); //removing all tiles from gameboard rect[a][b].setFill(Constant.realColor.TRANSPARENT); @@ -573,13 +564,12 @@ public class LaticeApplicationWindow extends Application { }else { //if it's not the first round of the game - System.out.println("OK3"); - System.out.println("Règle effectué"); + //not removing the tile from the rack player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b)); //verify if a tile is already placed if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == false ) { - ErrorLabel.setText("Error ! The tile can't be placed here because there is already a tile placed"); + gameInfoLabel.setText("Error ! The tile can't be placed here because there is already a tile placed"); rect[a][b].setFill(tileOnRect); }else { @@ -587,37 +577,41 @@ public class LaticeApplicationWindow extends Application { int nbr = referee.neighborRule(board , player.getRack().getListRackTile().get(indexTileClicked)); if (nbr == 0) { - ErrorLabel.setText("Error ! The tile isn't place next to another tile or there is no correspondance with the neighbor tiles !!"); + gameInfoLabel.setText("Error! The tile isn't placed next to another tile or there is no correspondance with the neighbor tiles!"); rect[a][b].setFill(Constant.realColor.TRANSPARENT); }else { - if (freeOrPayableTile == false) { - playerFX.setDiffScore(player, 2); + if (isFreePlacement == false) { + playerFX.setRemovePointsFromScore(player, 2); } if (nbr == 2) { System.out.println("Vous avez gagné 1 point"); - playerFX.setAddScore(player, 1); + gameInfoLabel.setText(player.getName() + "You won 1 point"); + playerFX.setAddPointsToScore(player, 1); }else if (nbr == 3) { System.out.println("Vous avez gagné 2 points"); - playerFX.setAddScore(player, 2); + gameInfoLabel.setText(player.getName() + "You won 2 points"); + playerFX.setAddPointsToScore(player, 2); }else if (nbr == 4) { System.out.println("Vous avez gagné 4 points"); - playerFX.setAddScore(player, 4); + gameInfoLabel.setText(player.getName() + "You won 4 points"); + playerFX.setAddPointsToScore(player, 4); } board.setGridBoardTile(player.getRack().getListRackTile().get(getIndexTileClicked()), a, b); tileDropped = true; - freeOrPayableTile = false; + isFreePlacement = false; System.out.println("tuile posé!"); //Sun rule if (referee.sunRule(board, player.getRack().getListRackTile().get(indexTileClicked))) { System.out.println("Vous avez gagné 2 points en mettant votre tuile sur un soleil"); - playerFX.setAddScore(player, 2); + gameInfoLabel.setText("Wow!" + player.getName() + "You won 2 points by placing a tile on a sun !"); + playerFX.setAddPointsToScore(player, 2); } } @@ -635,18 +629,12 @@ public class LaticeApplicationWindow extends Application { } } } - - - - - + //------------------------------------------------------------------------------- private void setDragnDropOnRack(HBox rackBox, Player player) { //Setting drag n drop on tiles for (int i=0; i< player.getRack().getRackTileImage().size(); i++) { int a = i; - System.out.println(a); - //HBox t = rackBox.getChildren().indexOf(rack); rackBox.getChildren().get(a).setOnDragDetected(new EventHandler() { @Override @@ -668,14 +656,13 @@ public class LaticeApplicationWindow extends Application { public void handle(DragEvent arg0) { if (tileDropped) { player.getRack().getListRackTile().remove(a); - rackImage = player.getRack().createTileImage(); + rackTileImage = player.getRack().createTileImage(); //Setting drag n drop on tiles - setDragnDropOnRack(rackImage, player); + setDragnDropOnRack(rackTileImage, player); - rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); - //setDragnDropOnRectangles(rect, board, referee, player); - borderPane.setBottom(rackImage); + rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); + borderPane.setBottom(rackTileImage); tileDropped = false; playerFX.setTilesRemaining(player); } @@ -691,10 +678,6 @@ public class LaticeApplicationWindow extends Application { return rootLayout; } - public static String getNameWinner() { - return nameWinner.getText(); - } - //getter to get the index of the mouse clicked tile public static int getIndexTileClicked() { return indexTileClicked; diff --git a/src/main/java/latice/controller/MainScreenController.java b/src/main/java/latice/controller/MainScreenController.java index 985a530..62e4a38 100644 --- a/src/main/java/latice/controller/MainScreenController.java +++ b/src/main/java/latice/controller/MainScreenController.java @@ -18,7 +18,9 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; import javafx.scene.shape.Rectangle; +import javafx.scene.web.WebView; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.util.Duration; @@ -69,30 +71,17 @@ public class MainScreenController extends LaticeApplicationWindow{ @FXML public void rulesButtonClicked(MouseEvent event) { System.out.println("rulesButtonClicked"); - Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); - Label secondLabel = new Label("Règles"); - //TODO règles à saisir - StackPane secondaryLayout = new StackPane(); - secondaryLayout.getChildren().add(secondLabel); - - Scene secondScene = new Scene(secondaryLayout, 230, 100); // New window (Stage) Stage newWindow = new Stage(); newWindow.setTitle("Règles du jeu Latice"); - newWindow.setScene(secondScene); - // Specifies the modality for new window - newWindow.initModality(Modality.WINDOW_MODAL); - - // Specifies the owner window - newWindow.initOwner(primaryStage); - - // Set position of window - newWindow.setX(primaryStage.getX() + 300); - newWindow.setY(primaryStage.getY() + 175); - - newWindow.show(); + WebView webView = new WebView(); + webView.getEngine().load("https://latice.com/how/#rules-objective"); + VBox videoContainer = new VBox(webView); + + newWindow.setScene(new Scene(videoContainer, 1100, 680)); + newWindow.show(); } // Event Listener on Rectangle[#exitButton].onMouseClicked @FXML diff --git a/src/main/java/latice/controller/PlayerNameInputController.java b/src/main/java/latice/controller/PlayerNameInputController.java index 40eabf6..3ceb0a2 100644 --- a/src/main/java/latice/controller/PlayerNameInputController.java +++ b/src/main/java/latice/controller/PlayerNameInputController.java @@ -47,6 +47,7 @@ public class PlayerNameInputController { public void validBtnClicked(MouseEvent event) { System.out.println("valid Button Clicked"); + //Verifying if player's names are correct if(nomJoueur1.getText().length() < 3 || nomJoueur1.getText().length() > 16) { label1.setVisible(true); } @@ -71,7 +72,7 @@ public class PlayerNameInputController { mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); - //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); + //Starting game mainScreenController.startGameInstruction(false); } } diff --git a/src/main/java/latice/model/Constant.java b/src/main/java/latice/model/Constant.java index 564b1c0..929e1d0 100644 --- a/src/main/java/latice/model/Constant.java +++ b/src/main/java/latice/model/Constant.java @@ -23,7 +23,7 @@ public class Constant { public static final int BOX_WIDTH = 52; - public static final int ACTION_BUTTONS_WIDTH = 120; + public static final int ACTION_BUTTONS_WIDTH = 170; public static final int ACTION_BUTTONS_HEIGHT = 45; diff --git a/src/main/java/latice/model/Player.java b/src/main/java/latice/model/Player.java index 8f42dbd..f01ca15 100644 --- a/src/main/java/latice/model/Player.java +++ b/src/main/java/latice/model/Player.java @@ -53,13 +53,13 @@ public class Player { return this.deck.getListTile().size() + this.rack.getListRackTile().size(); } - public Integer addScore(Integer value) { + public Integer addPointsToScore(Integer value) { int newScore = this.score.getScore()+value; this.score.setScore(newScore); return this.score.getScore(); } - public Integer diffScore(Integer value) { + public Integer removePointsFromScore(Integer value) { int newScore = this.score.getScore()-value; this.score.setScore(newScore); return this.score.getScore(); diff --git a/src/main/java/latice/model/Rules.java b/src/main/java/latice/model/Rules.java index 4c15aaf..a0d634c 100644 --- a/src/main/java/latice/model/Rules.java +++ b/src/main/java/latice/model/Rules.java @@ -112,7 +112,7 @@ public class Rules { }else { System.out.println("-----------------------------"); if (this.sunRule(board, tile)){ - player.addScore(2); + player.addPointsToScore(2); } int nbr = this.neighborRule(board, tile); if (nbr == 0) { @@ -122,13 +122,13 @@ public class Rules { }else { if (nbr == 2) { System.out.println("Vous avez gagné 1 point"); - player.addScore(1); + player.addPointsToScore(1); }else if (nbr == 3) { System.out.println("Vous avez gagné 2 points"); - player.addScore(2); + player.addPointsToScore(2); }else if (nbr == 4) { System.out.println("Vous avez gagné 4 points"); - player.addScore(4); + player.addPointsToScore(4); } return true; diff --git a/src/main/java/latice/model/window/PlayGame.java b/src/main/java/latice/model/window/PlayGame.java deleted file mode 100644 index 684dae4..0000000 --- a/src/main/java/latice/model/window/PlayGame.java +++ /dev/null @@ -1,264 +0,0 @@ -package latice.model.window; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javafx.event.EventHandler; -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.input.ClipboardContent; -import javafx.scene.input.DragEvent; -import javafx.scene.input.Dragboard; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.TransferMode; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundImage; -import javafx.scene.layout.BackgroundPosition; -import javafx.scene.layout.BackgroundRepeat; -import javafx.scene.layout.BackgroundSize; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; -import javafx.scene.paint.ImagePattern; -import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; -import javafx.scene.text.FontWeight; -import javafx.scene.text.Text; -import javafx.stage.Stage; -import latice.model.Color; -import latice.model.Player; -import latice.model.Shape; -import latice.model.Tile; -import latice.model.console.Deck; -import latice.model.console.Rack; - -public class PlayGame { - - Image image = new Image("backgroundLatice.png"); - ImageView imageView = new ImageView(image); - - Tile blueBird = new Tile(Color.NAVYBLUE, Shape.BIRD); - Tile greenLeaf = new Tile(Color.GREEN, Shape.FEATHER); - Tile redFlower = new Tile(Color.RED, Shape.FLOWER); - - ArrayList listRackTile; - ArrayList listTileImage; - ArrayList listOfTile = new ArrayList(); - Map assocRectangleTile = new HashMap(); - static StackPane rootLayout; - private Label namePlayer1 = new Label("Anonyme"); - private Label namePlayer2 = new Label("Anonyme"); - - public static int indexTileClicked; - - - //settings players - public Player player1; - public Player player2; - - //root layout - BorderPane borderPane = new BorderPane(); - - //StackPane for background image + BorderPane root onto it - StackPane root = new StackPane(); - - static Stage primaryStageCopy; - - - int confirmBtnClickedCount; - - public Stage playGame(Stage StageToGame) { - //-------------------------------------------------------------------------------------- - //Title - Text title = new Text("Latice"); - title.setFont(new Font(30)); - borderPane.setTop(title); - borderPane.setAlignment(title, Pos.CENTER); - //-------------------------------------------------------------------------------------- - //Image - Pane pane = new Pane(); - BackgroundImage myBG= new BackgroundImage(image, - BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, - BackgroundSize.DEFAULT); - root.setBackground(new Background(myBG)); - - //-------------------------------------------------------------------------------------- - //-------------------------------------------------------------------------------------- - //###################### creating all rectangles and DragnDrop ######################// - RectangleFX rectFX = new RectangleFX(); - rectFX.createRectangle(borderPane, pane); - rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, confirmBtnClickedCount); - rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, confirmBtnClickedCount); - //-------------------------------------------------------------------------------------- - - borderPane.setCenter(pane); - //-------------------------------------------------------------------------------------- - - - //-------------------------------------------------------------------------------------- - //Rack - HBox rackBox = new HBox(); - - rackBox.setSpacing(10); - rackBox.setPadding(new Insets(15,20, 10,10)); - - - //Creating tiles - for (Color color : Color.values()) { - for (Shape shape : Shape.values()) { - Tile tile = new Tile(color, shape); - - listOfTile.add(tile); - - } - } - - System.out.println("-----------------"); - System.out.println("Notre Deck :"); - Deck deck = new Deck(listOfTile); - System.out.println("-----------------"); - Rack rack = new Rack(deck); - System.out.println("-----------------"); - //deck.displayListTile(); - - - - //Confirm Button - Image checkMark = new Image("checkMark.png"); - ImageView checkMarkView = new ImageView(checkMark); - Button confirmButton = new Button("Confirm", checkMarkView); - - confirmButton.setOnMouseClicked(new EventHandler() { - - @Override - public void handle(MouseEvent arg0) { - - confirmBtnClickedCount++; - System.out.println("confirmed placement"); - - } - - }); - - //With Image - Rack rack2 = new Rack(deck); - HBox rackImage = rack2.createTileImage(); - rackImage.getChildren().add(confirmButton); - rackImage.setMargin(rackImage.getChildren().get(4), new Insets(0,150,0,0)); - borderPane.setBottom(rackImage); - - //Adding lists to Arraylists - listRackTile = rack2.getListRackTile(); - System.out.println(listRackTile); - listTileImage = rack2.getRackTileImage(); - System.out.println("listTileImge : " + listTileImage); - - - //------------------------------------------------------------------------ - - - //Setting OnDragDetected on tiles - setDragnDropOnRack(rackImage); - - System.out.println((indexTileClicked)); - ImagePattern imagePattern = new ImagePattern(listTileImage.get(indexTileClicked)); - - - - //rules / referee implementaion - - this.transition(namePlayer1, namePlayer2); - //root.setLeft(namePlayer1); - - //###################### display name, score and deck of each player ######################// - HBox players = new HBox(); - - ArrayList 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("Anonyme", FontWeight.BOLD, 20)); - name.setText("Anonyme"); - - Text score = new Text(); - score.setText("Score : " + nameplayer.getScore()); - - Text nbrOfTiles = new Text(); - nbrOfTiles.setText("Tuiles restantes : " + nameplayer.getNumberOfTilesRemaining()); - - player.getChildren().addAll(name, score, nbrOfTiles); - player.setSpacing(5); - - players.getChildren().add(player); - players.setMargin(player, new Insets(50,0,0,55)); - } - System.out.println("largeur : " + borderPane.getMaxWidth()); - players.setSpacing(850); - - //-------------------------------------------------------------------------------------- - setPrimaryStage(StageToGame); - setRootLayout(root); - root.getChildren().addAll(players, borderPane); - - return StageToGame; - - } - - public void transition(Label player1, Label player2) { - - borderPane.setLeft(player1); - borderPane.setRight(player2); - } - - public void setPrimaryStage(Stage primaryStage) { - this.primaryStageCopy = primaryStage; - } - - public static void setRootLayout(StackPane root) { - rootLayout = root; - } - - private void setDragnDropOnRack(HBox rackImage) { - for (int i=0; i<5; i++) { - int index = i; - rackImage.getChildren().get(index).setOnDragDetected(new EventHandler() { - - @Override - public void handle(MouseEvent arg0) { - Dragboard dragboard = rackImage.getChildren().get(index).startDragAndDrop(TransferMode.ANY); - ClipboardContent content = new ClipboardContent(); - dragboard.setDragView(listTileImage.get(index)); - content.putString("Hello !"); - indexTileClicked = index; - //setIndexTileClicked(index); - dragboard.setContent(content); - arg0.consume(); - - } - - }); - - rackImage.getChildren().get(index).setOnDragDone(new EventHandler() { - - @Override - public void handle(DragEvent arg0) { - - } - - }); - } - } - - -} diff --git a/src/main/java/latice/model/window/PlayerFX.java b/src/main/java/latice/model/window/PlayerFX.java index 1a5799c..cd2a7bc 100644 --- a/src/main/java/latice/model/window/PlayerFX.java +++ b/src/main/java/latice/model/window/PlayerFX.java @@ -19,51 +19,44 @@ public class PlayerFX { private VBox infoPlayer; public VBox displayPlayers(StackPane root, Player player) { - //###################### display name, score and deck of each player ######################// - //HBox players = new HBox(); + //-------------- display name, score and deck of each player ---------------// + + this.infoPlayer = new VBox(); - //ArrayList allPlayers = new ArrayList<>(); - //allPlayers.add(player1); - //allPlayers.add(player2); + this.name = new Text(); + this.name.setFont(Font.font(player.getName(), FontWeight.BOLD, 20)); + this.name.setText(player.getName()); - //for (Player namePlayer : allPlayers ) { - this.infoPlayer = new VBox(); - - this.name = new Text(); - this.name.setFont(Font.font(player.getName(), FontWeight.BOLD, 20)); - this.name.setText(player.getName()); - - this.score = new Text(); - this.score.setText("Score : " + player.getScore()); - - this.nbrOfTiles = new Text(); - this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining()); - - this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles); - this.infoPlayer.setSpacing(5); - - //players.getChildren().add(infoPlayer); - //players.setMargin(infoPlayer, new Insets(50,0,0,55)); - //} + this.score = new Text(); + this.score.setText("Score : " + player.getScore()); + + this.nbrOfTiles = new Text(); + this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining()); + + this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles); + this.infoPlayer.setSpacing(5); - //players.setSpacing(850); return this.infoPlayer; } + //setting the player's nickname who plays in red public void setFillName(javafx.scene.paint.Color color) { name.setFill(color); } - public void setAddScore(Player player, Integer score) { - player.addScore(score); + //adding points to player + public void setAddPointsToScore(Player player, Integer score) { + player.addPointsToScore(score); this.score.setText("Score : " + player.getScore()); } - public void setDiffScore(Player player, Integer score) { - player.diffScore(score); + //Removing points from player + public void setRemovePointsFromScore(Player player, Integer score) { + player.removePointsFromScore(score); this.score.setText("Score : " + player.getScore()); } + //Setting the tiles remaining public void setTilesRemaining(Player player) { this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining()); } diff --git a/src/test/java/latice/LaticeTest.java b/src/test/java/latice/LaticeTest.java index 379c4f9..40d7cac 100644 --- a/src/test/java/latice/LaticeTest.java +++ b/src/test/java/latice/LaticeTest.java @@ -202,10 +202,10 @@ class LaticeTest { assertEquals(0, player.getScore()); assertEquals(rack, player.getRack()); - player.addScore(2); + player.addPointsToScore(2); assertEquals(2, player.getScore()); - player.diffScore(1); + player.removePointsFromScore(1); assertEquals(1, player.getScore()); }