Merge branch 'master' into 'Display_name_player_in_window'
# Conflicts: # src/main/java/latice/application/LaticeApplicationWindow.javamaster
commit
ece584542c
6
pom.xml
6
pom.xml
|
@ -17,6 +17,12 @@
|
|||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -66,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<Tile> listRackTile;
|
||||
ArrayList<Image> listTileImage;
|
||||
|
@ -93,10 +90,10 @@ public class LaticeApplicationWindow extends Application {
|
|||
|
||||
static Stage primaryStageCopy;
|
||||
StackPane parentStackPane = new StackPane();
|
||||
Label moonErrorLabel = new Label();
|
||||
|
||||
int validateBtnClickedCount;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(args);
|
||||
|
@ -113,11 +110,16 @@ 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();
|
||||
BackgroundImage myBG= new BackgroundImage(image,
|
||||
|
@ -200,7 +202,8 @@ public class LaticeApplicationWindow extends Application {
|
|||
System.out.println("-----------------");
|
||||
//deck.displayListTile();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Confirm Button
|
||||
Image checkMark = new Image("checkMark.png");
|
||||
|
@ -212,18 +215,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<MouseEvent>() {
|
||||
|
||||
@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
|
||||
|
@ -235,8 +266,7 @@ public class LaticeApplicationWindow extends Application {
|
|||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
|
||||
//Setting OnDragDetected on tiles
|
||||
//Setting drag n drop on tiles
|
||||
setDragnDropOnRack(rackImage);
|
||||
|
||||
System.out.println((indexTileClicked));
|
||||
|
@ -250,20 +280,57 @@ public class LaticeApplicationWindow extends Application {
|
|||
rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount);
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
//rules / referee implementaion
|
||||
|
||||
this.transition(namePlayer1, namePlayer2);
|
||||
//root.setLeft(namePlayer1);
|
||||
|
||||
//###################### display name, score and deck of each player ######################//
|
||||
HBox players = new HBox();
|
||||
|
||||
ArrayList<Player> allPlayers = new ArrayList<>();
|
||||
allPlayers.add(player1);
|
||||
allPlayers.add(player2);
|
||||
|
||||
for (Player nameplayer : allPlayers ) {
|
||||
VBox player = new VBox();
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
if (arg0.isDropCompleted() == false) {
|
||||
r[a][b].setFill(realColor.TRANSPARENT);
|
||||
}
|
||||
arg0.consume();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
r[a][b].setOnDragOver(new EventHandler <DragEvent>() {
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
arg0.acceptTransferModes(TransferMode.ANY);
|
||||
arg0.consume();
|
||||
}
|
||||
});
|
||||
|
||||
r[a][b].setOnDragDropped(new EventHandler<DragEvent>() {
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
System.out.println("entered");
|
||||
Dragboard dragboard = arg0.getDragboard();
|
||||
|
||||
r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked())));
|
||||
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");
|
||||
}else {
|
||||
moonErrorLabel.setText("Error ! Please place the first tile on the moon");
|
||||
//removing all tiles from gameboard
|
||||
for(int i=0; i<NUMBER_OF_BOX_ON_ONE_LINE; i++) {
|
||||
for(int j=0; j<NUMBER_OF_BOX_ON_ONE_LINE; j++) {
|
||||
r[i][j].setFill(realColor.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
System.out.println("Please place first Tile on MOON");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
arg0.consume();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
Text name = new Text();
|
||||
name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20));
|
||||
|
@ -307,26 +374,25 @@ public class LaticeApplicationWindow extends Application {
|
|||
|
||||
|
||||
private void setDragnDropOnRack(HBox rackImage) {
|
||||
//Setting drag n drop on tiles
|
||||
for (int i=0; i<5; i++) {
|
||||
int index = i;
|
||||
rackImage.getChildren().get(index).setOnDragDetected(new EventHandler<MouseEvent>() {
|
||||
int a = i;
|
||||
rackImage.getChildren().get(a).setOnDragDetected(new EventHandler<MouseEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(MouseEvent arg0) {
|
||||
Dragboard dragboard = rackImage.getChildren().get(index).startDragAndDrop(TransferMode.ANY);
|
||||
Dragboard dragboard = rackImage.getChildren().get(a).startDragAndDrop(TransferMode.ANY);
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
dragboard.setDragView(listTileImage.get(index));
|
||||
dragboard.setDragView(listTileImage.get(a));
|
||||
content.putString("Hello !");
|
||||
indexTileClicked = index;
|
||||
//setIndexTileClicked(index);
|
||||
setIndexTileClicked(a);
|
||||
dragboard.setContent(content);
|
||||
arg0.consume();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
rackImage.getChildren().get(index).setOnDragDone(new EventHandler<DragEvent>() {
|
||||
rackImage.getChildren().get(a).setOnDragDone(new EventHandler<DragEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
|
||||
<BorderPane xmlns:fx="http://javafx.com/fxml/1">
|
||||
<!-- TODO Add Nodes -->
|
||||
|
||||
<BorderPane prefHeight="241.0" prefWidth="386.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17">
|
||||
<center>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Button fx:id="replayBtn" layoutX="42.0" layoutY="163.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="127.0" textFill="TRANSPARENT" />
|
||||
<Button fx:id="quitBtn" layoutX="221.0" layoutY="163.0" mnemonicParsing="false" prefHeight="51.0" prefWidth="129.0" textFill="TRANSPARENT" />
|
||||
<ImageView fitHeight="241.0" fitWidth="386.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../../../resources/GameFinishedImage.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<Label alignment="CENTER_RIGHT" layoutX="4.0" layoutY="73.0" prefHeight="22.0" prefWidth="154.0" textAlignment="CENTER" />
|
||||
</children>
|
||||
</Pane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 393 B |
|
@ -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<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue