From 149f49f7f886382a4c61ea378c3d8cdf3b04b60f Mon Sep 17 00:00:00 2001 From: cemal Date: Wed, 1 Jun 2022 14:50:01 +0200 Subject: [PATCH 1/2] Step 7 : change Rack implemented and working sucessfully --- .../application/LaticeApplicationWindow.java | 130 ++++++++++++------ .../java/latice/view/GameFinishedScreen.fxml | 24 +++- src/main/resources/changeIcon.png | Bin 0 -> 393 bytes 3 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 src/main/resources/changeIcon.png diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index c7cd707..9e41a1f 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -33,6 +33,7 @@ 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; @@ -65,9 +66,6 @@ public class LaticeApplicationWindow extends Application { 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; @@ -86,10 +84,10 @@ public class LaticeApplicationWindow extends Application { StackPane stackPane = new StackPane(); static Stage primaryStageCopy; StackPane parentStackPane = new StackPane(); + Label moonErrorLabel = new Label(); int validateBtnClickedCount; - public static void main(String[] args) { Application.launch(args); @@ -106,10 +104,15 @@ public class LaticeApplicationWindow extends Application { //Title + VBox topVbox = new VBox(); Text title = new Text("Latice"); title.setFont(new Font(30)); - root.setTop(title); - root.setAlignment(title, Pos.CENTER); + topVbox.getChildren().add(title); + topVbox.setAlignment(Pos.CENTER); + moonErrorLabel.setFont(new Font(20)); + moonErrorLabel.setTextFill(realColor.RED); + topVbox.getChildren().add(moonErrorLabel); + root.setTop(topVbox); //Image Pane pane = new Pane(); @@ -170,7 +173,8 @@ public class LaticeApplicationWindow extends Application { System.out.println("-----------------"); //deck.displayListTile(); - + + //Confirm Button Image checkMark = new Image("checkMark.png"); @@ -182,18 +186,46 @@ public class LaticeApplicationWindow extends Application { @Override public void handle(MouseEvent arg0) { - validateBtnClickedCount++; + System.out.println("confirmed placement"); + validateBtnClickedCount++; + } }); + //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)); + + + //RackChange Button + Image changeIconImage = new Image("changeIcon.png"); + ImageView changeIconView = new ImageView(changeIconImage); + Button changeButton = new Button("Change Rack", changeIconView); + + + changeButton.setOnMouseClicked(new EventHandler() { + + @Override + public void handle(MouseEvent arg0) { + + + System.out.println("Changing Rack"); + rack2.changeRack(); + + rackImage.getChildren().clear(); + + rackImage.getChildren().addAll(rack2.createTileImage(), confirmButton, changeButton); + + //Setting drag n drop on tiles + setDragnDropOnRack(rackImage); + } + + }); + rackImage.getChildren().addAll(confirmButton, changeButton); root.setBottom(rackImage); //Adding lists to Arraylists @@ -205,34 +237,8 @@ public class LaticeApplicationWindow extends Application { //------------------------------------------------------------------------ - - //Setting OnDragDetected on tiles - for (int i=0; i<5; i++) { - int a = i; - rackImage.getChildren().get(a).setOnDragDetected(new EventHandler() { - - @Override - public void handle(MouseEvent arg0) { - Dragboard dragboard = rackImage.getChildren().get(a).startDragAndDrop(TransferMode.ANY); - ClipboardContent content = new ClipboardContent(); - dragboard.setDragView(listTileImage.get(a)); - content.putString("Hello !"); - setIndexTileClicked(a); - dragboard.setContent(content); - arg0.consume(); - } - - }); - - rackImage.getChildren().get(a).setOnDragDone(new EventHandler() { - - @Override - public void handle(DragEvent arg0) { - - } - - }); - } + //Setting drag n drop on tiles + setDragnDropOnRack(rackImage); System.out.println((indexTileClicked)); ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked())); @@ -286,11 +292,20 @@ public class LaticeApplicationWindow extends Application { arg0.setDropCompleted(true); assocRectangleTile.put(r[a][b], listRackTile.get(getIndexTileClicked())); System.out.println(assocRectangleTile.toString()); + moonErrorLabel.setText(""); if (validateBtnClickedCount == 0){ if (r[a][b] == r[4][4]) { - System.out.println("MOON valid placement"); + System.out.println("MOON valid placement"); }else { + moonErrorLabel.setText("Error ! Please place the first tile on the moon"); + //removing all tiles from gameboard + for(int i=0; i() { + + @Override + public void handle(MouseEvent arg0) { + Dragboard dragboard = rackImage.getChildren().get(a).startDragAndDrop(TransferMode.ANY); + ClipboardContent content = new ClipboardContent(); + dragboard.setDragView(listTileImage.get(a)); + content.putString("Hello !"); + setIndexTileClicked(a); + dragboard.setContent(content); + arg0.consume(); + } + + }); + + rackImage.getChildren().get(a).setOnDragDone(new EventHandler() { + + @Override + public void handle(DragEvent arg0) { + + } + + }); + } + } public static void setRootLayout(StackPane root) { rootLayout = root; } @@ -364,5 +411,10 @@ public class LaticeApplicationWindow extends Application { MSC.setParentStackPane(parentStackPane); primaryStageCopy.setTitle("working"); } + + public void displayMoonError() { + } + + } diff --git a/src/main/java/latice/view/GameFinishedScreen.fxml b/src/main/java/latice/view/GameFinishedScreen.fxml index 95bf597..de9474d 100644 --- a/src/main/java/latice/view/GameFinishedScreen.fxml +++ b/src/main/java/latice/view/GameFinishedScreen.fxml @@ -1,8 +1,26 @@ + + + + + - - + + +
+ + +
- diff --git a/src/main/resources/changeIcon.png b/src/main/resources/changeIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..73da4b0d88d5c3b5bfaa672c4714530a624bed6c GIT binary patch literal 393 zcmV;40e1e0P)zbsxq{E& zCTF0fOo3daO=C?8mc${%fw21}7nVHp=l}K0EQ}z8Fq5DdFVq*VxE#i$~QDQ1^){3J;1yAXn1?dg}bmPo!S@#J6kpUQtx(hbkVfhPHw1u0iEBbAIQffCi@AYkBk46)(dTTMb7;^qh%p+6jxPfOE2DY9_R nDapDr&q>X?^hb$qy|#P+9ZF|6^1*y$ literal 0 HcmV?d00001 From a7bf2cfa4e6e7a54d5e910da76d2367b7cd2bc5e Mon Sep 17 00:00:00 2001 From: cemal Date: Wed, 1 Jun 2022 18:51:10 +0200 Subject: [PATCH 2/2] added test cases --- pom.xml | 6 + src/test/java/latice/LaticeTest.java | 227 +++++++++++++++++++++++++++ 2 files changed, 233 insertions(+) create mode 100644 src/test/java/latice/LaticeTest.java diff --git a/pom.xml b/pom.xml index 8d6d7fe..7b09c1b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,12 @@ 5.8.2 test + + org.assertj + assertj-core + 3.4.1 + test + diff --git a/src/test/java/latice/LaticeTest.java b/src/test/java/latice/LaticeTest.java new file mode 100644 index 0000000..6613aff --- /dev/null +++ b/src/test/java/latice/LaticeTest.java @@ -0,0 +1,227 @@ +package latice; + +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; + +class LaticeTest { + + //VEUILLEZ SAISIR Marc COMME NOM DU JOUEUR DANS LA CONSOLE + + + @Test + void should_return_tile_with_position_shape_color() { + //Arrange + Tile tile = new Tile(Color.GREEN, Shape.BIRD); + final int COLUMN = 10; + final int ROW = 10; + + + //Act + Color returnedColor = tile.getColor(); + Shape returnedShape = tile.getShape(); + tile.setPosition(new Position(ROW, COLUMN)); + Integer returnedRowPosition = tile.getPositionRow(); + Integer returnedColumnPosition = tile.getPositionColumn(); + + + //Assert + assertEquals(Color.GREEN, returnedColor); + assertEquals(Shape.BIRD, returnedShape); + assertEquals(ROW, returnedRowPosition); + assertEquals(COLUMN, returnedColumnPosition); + + } + + @Test + void should_return_good_score() { + //Arrange + Score score = new Score(); + final int POINTS = 0; + + //Act + score.setScore(POINTS); + + //Assert + assertEquals(POINTS, score.getScore()); + } + + @Test + void deck_test(){ + //Arrange + ArrayList listOfTile = new ArrayList(); + Deck deck; + + //Act + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + deck = new Deck(listOfTile); + + //Assert + assertEquals(listOfTile, deck.getListTile()); + + + } + + @Test + void should_change_rack() { + //Arrange + ArrayList listOfTile = new ArrayList(); + Deck deck; + Deck deck2; + Rack rack; + Rack rack2; + + //Act + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + deck = new Deck(listOfTile); + deck2 = new Deck(listOfTile); + + rack = new Rack(deck); + rack2 = new Rack(deck2); + + //Assert + assertEquals(5, rack.getListRackTile().size()); + + //changeRack Test + rack2.changeRack(); + + assertThat(rack.getListRackTile()) + .isNotEqualTo(rack2.getListRackTile()); + + + } + + @Test + void should_set_new_rack() { + //Arrange + ArrayList listOfTile = new ArrayList(); + Deck deck; + Deck deck2; + Rack rack; + Rack rack2; + + //Act + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + deck = new Deck(listOfTile); + deck2 = new Deck(listOfTile); + rack = new Rack(deck); + rack2 = new Rack(deck2); + rack.setListRackTile(rack2.getListRackTile()); + + //Assert + assertEquals(rack.getListRackTile(), rack2.getListRackTile()); + } + + @Test + void should_remove_tile_from_rack() { + //Arrange + ArrayList listOfTile = new ArrayList(); + Deck deck; + Rack rack; + + //Act + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + deck = new Deck(listOfTile); + rack = new Rack(deck); + rack.removeTile(rack.getListRackTile().get(0)); + + //Assert + assertEquals(4, rack.getListRackTile().size()); + + } + + @Test + void test_getters_and_seters_of_Player_class() { + //Arrange + ArrayList listOfTile = new ArrayList(); + Deck deck; + Rack rack; + + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + deck = new Deck(listOfTile); + rack = new Rack(deck); + Player player = new Player("Marc", new Score(), deck, rack); + + //Act + + + //Assert + assertEquals("Marc", player.getName()); + assertEquals(0, player.getScore()); + assertEquals(rack, player.getRack()); + + player.addScore(2); + assertEquals(2, player.getScore()); + + player.diffScore(1); + assertEquals(1, player.getScore()); + + } + + + + /*@Test + void () { + //Arrange + + //Act + + //Assert + + }*/ + + + +}