Compare commits

..

No commits in common. "ccb61b5ef8594d75123eb955d1c38d8d91d66b53" and "5d3ff112ebdd320d1d097fb0402cc361fb0dcd44" have entirely different histories.

13 changed files with 604 additions and 456 deletions

View File

@ -20,10 +20,13 @@ public class LaticeApplicationConsole {
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
//System.out.println("Hello Latice !");
/*
for (Color color : Color.values()) { for (Color color : Color.values()) {
for (Shape shape : Shape.values()) { for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape); Tile tile = new Tile(color, shape);
System.out.println(color.getStringColor() + shape.getStringShape()+ ".png");
listOfTile.add(tile); listOfTile.add(tile);
@ -32,20 +35,85 @@ public class LaticeApplicationConsole {
System.out.println("-----------------");
System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile);
deck.displayListTile();
System.out.println("-----------------");
Rack rack = new Rack(deck);
System.out.println("-----------------");
deck.displayListTile();
System.out.println("-----------------");
GameBoard board = new GameBoard();
board.displayGameBoard();
System.out.println("-----------------");
board.setGridBoard(" NV ", 4, 4);
board.displayGameBoard();
System.out.println("-----------------");
Score scorePlayer1 = new Score();
Score scorePlayer2 = new Score();
Player player1 = new Player("player1", scorePlayer1);
Player player2 = new Player("player2", scorePlayer2);
System.out.println(player1.getName() + " a " + scorePlayer1.getScore() +" points");
System.out.println(player2.getName() + " a " + scorePlayer2.getScore() +" points");
rack.displayRack();
*/
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);
}
}
System.out.println("-----------------");
//System.out.println("Notre Deck :");
//Deck deck1 = new Deck(listOfTile);
//Deck deck2 = new Deck(listOfTile);
//deck1.displayListTile();
System.out.println("-----------------");
//Rack rack1 = new Rack(deck1);
//Rack rack2 = new Rack(deck2);
//Score scorePlayer1 = new Score();
//Score scorePlayer2 = new Score();
//Player player1 = new Player("player1", scorePlayer1);
//Player player2 = new Player("player2", scorePlayer2);
System.out.println("-----------------");
//GameBoard board = new GameBoard();
//board.displayGameBoard();
System.out.println("-----------------");
//System.out.println(player1.getName() + " a " + scorePlayer1.getScore() +" points");
//System.out.println(player2.getName() + " a " + scorePlayer2.getScore() +" points");
//rack1.displayRack();
System.out.println("Hello Latice !"); System.out.println("Hello Latice !");
System.out.println("-----------------"); System.out.println("-----------------");
Deck deck1 = new Deck(listOfTile); Deck deck1 = new Deck(listOfTile);
Deck deck2 = new Deck(listOfTile); Deck deck2 = new Deck(listOfTile);
Rack rack1 = new Rack(deck1);
Rack rack2 = new Rack(deck2);
Score scorePlayer1 = new Score();
Score scorePlayer2 = new Score();
Player player1 = new Player("player1", deck1); Player player1 = new Player("player1", deck1);
Player player2 = new Player("player2", deck2); Player player2 = new Player("player2", deck2);
System.out.println("-----------------");
GameBoard board = new GameBoard(); GameBoard board = new GameBoard();
board.displayGameBoard(); board.displayGameBoard();
System.out.println(Objects.equals(board.getGridBoard()[1][0], Tile.class));
Scanner play = new Scanner(System.in); Scanner play = new Scanner(System.in);
Player player; Player player;
Boolean round; Boolean round;
@ -69,17 +137,15 @@ public class LaticeApplicationConsole {
while (round) { while (round) {
player.getRack().displayRack(); player.getRack().displayRack();
System.out.println("Vous avez " + player.getScore() +" points, que voulez-vous faire ?\n" System.out.println("Vous avez " + player.getScore() +" points, que voulez-vous faire ?\n"
+ " 1. Jouer une Tuile\n" + " 1. Jouer une Tuile (à partir de la deuxième tuile jouée, cela coûtera 2 points)\n"
+ " 2. Acheter une action supplémentaire(coûte 2 points)\n" + " 2. Acheter une action supplémentaire\n"
+ " 3. Changer le Rack et passer(coûte 3 points)\n" + " 3. Changer le Rack et passer(coûte 3 points)\n"
+ " 4. Passer\n"); + " 4. Passer\n");
System.out.print("Choix : "); System.out.print("Choix : ");
int choiceMenu = Integer.parseInt(play.next()); int choiceMenu = Integer.parseInt(play.next());
switch(choiceMenu) { switch(choiceMenu) {
case 1: if (freeTile) { case 1: if (freeTile) {
freeTile = false;
Boolean rulesCheck = false; Boolean rulesCheck = false;
while (rulesCheck == false) { while (rulesCheck == false) {
@ -99,26 +165,18 @@ public class LaticeApplicationConsole {
player.getRack().removeTile(tile); player.getRack().removeTile(tile);
board.displayGameBoard(); board.displayGameBoard();
}else {
System.out.println("Vous n'avez pas acheter une action pour jouer un autre tuile dans ce tour ! Veuillez en acheter une ou passer votre tour !");
} }
break; break;
case 2: case 2:
if (freeTile) { if (player.getScore()>=3) {
System.out.println("Vous avez dejà une action pour jouer une tuile ! Veuillez jouer votre tuile d'abord pour ensuite acheter une nouvelle action pour jouer une autre tuile !"); //Donner une action supplémentaire et enlever 3 points au joueur
}else {
if (player.getScore()>=2) {
//Buy another action and remove 2 points from score
player.Play(play, board, 0); player.Play(play, board, 0);
player.removePointsFromScore(2); player.diffScore(2);
freeTile = true;
}else { }else {
System.out.println("Il vous faut 2 points pour acheter une nouvelle action !"); System.out.println("Il vous faut 2 points pour acheter une nouvelle action !");
} }
}
break; break;

View File

@ -63,8 +63,8 @@ public class LaticeApplicationWindow extends Application {
//lists for tiles //lists for tiles
ArrayList<Tile> listRackTile; ArrayList<Tile> listRackTile;
ArrayList<Image> listOfTilesInRack; ArrayList<Image> listRackImage;
//ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
static StackPane rootLayout; static StackPane rootLayout;
public static int indexTileClicked; public static int indexTileClicked;
@ -92,7 +92,7 @@ public class LaticeApplicationWindow extends Application {
Paint tileOnRect; Paint tileOnRect;
//tile is free when it's the first tile put but tile is payable after //tile is free when it's the first tile put but tile is payable after
Boolean isFreePlacement = true; Boolean freeOrPayableTile = true;
public static BorderPane borderPane = new BorderPane(); public static BorderPane borderPane = new BorderPane();
@ -102,9 +102,9 @@ public class LaticeApplicationWindow extends Application {
Stage primaryStageCopy; Stage primaryStageCopy;
StackPane parentStackPane = new StackPane(); StackPane parentStackPane = new StackPane();
Label gameInfoLabel = new Label(); Label ErrorLabel = new Label();
HBox rackTileImage; HBox rackImage;
static Label nameWinner = new Label(); static Label nameWinner = new Label();
int confirmBtnClickedCount; int confirmBtnClickedCount;
@ -152,7 +152,7 @@ public class LaticeApplicationWindow extends Application {
stage.setScene(menu); stage.setScene(menu);
parentStackPane.getChildren().remove(root); parentStackPane.getChildren().remove(root);
parentStackPane.getChildren().add(root); //parentStackPane.getChildren().add(root);
parentStackPane.getChildren().remove(menuBorderPane); parentStackPane.getChildren().remove(menuBorderPane);
}else { }else {
@ -186,9 +186,9 @@ public class LaticeApplicationWindow extends Application {
topVbox.setAlignment(Pos.CENTER); topVbox.setAlignment(Pos.CENTER);
//error label for displaying errors //error label for displaying errors
gameInfoLabel.setFont(new Font(20)); ErrorLabel.setFont(new Font(20));
gameInfoLabel.setTextFill(Constant.realColor.RED); ErrorLabel.setTextFill(Constant.realColor.RED);
topVbox.getChildren().add(gameInfoLabel); topVbox.getChildren().add(ErrorLabel);
borderPane.setTop(topVbox); borderPane.setTop(topVbox);
//background image //background image
@ -260,21 +260,21 @@ public class LaticeApplicationWindow extends Application {
//Creating tiles //Creating tiles
/*for (Color color : Color.values()) { for (Color color : Color.values()) {
for (Shape shape : Shape.values()) { for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape); Tile tile = new Tile(color, shape);
listOfTile.add(tile); listOfTile.add(tile);
} }
}*/ }
/*System.out.println("-----------------"); System.out.println("-----------------");
System.out.println("Notre Deck :"); System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile); Deck deck = new Deck(listOfTile);
System.out.println("-----------------"); System.out.println("-----------------");
Rack rack = new Rack(deck); Rack rack = new Rack(deck);
System.out.println("-----------------");*/ System.out.println("-----------------");
//Player //Player
@ -286,7 +286,7 @@ public class LaticeApplicationWindow extends Application {
//Confirm Button //Confirm Button
Image checkMark = new Image("checkMark.png"); Image checkMark = new Image("checkMark.png");
ImageView checkMarkView = new ImageView(checkMark); ImageView checkMarkView = new ImageView(checkMark);
confirmButton = new Button("End Turn", checkMarkView); confirmButton = new Button("Confirm", checkMarkView);
confirmButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); confirmButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH);
confirmButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); confirmButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
@ -299,11 +299,11 @@ public class LaticeApplicationWindow extends Application {
changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
//Buy another action Button //Buy another action Button
/*Image buyActionImage = new Image("buyAction.png"); Image buyActionImage = new Image("buyAction.png");
ImageView buyActionView = new ImageView(buyActionImage); ImageView buyActionView = new ImageView(buyActionImage);
buyActionButton = new Button("Buy Action (2 points)", buyActionView); buyActionButton = new Button("Buy Action", buyActionView);
buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH);
buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);*/ buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() { confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
//confirming the end of the round and switching round //confirming the end of the round and switching round
@ -320,13 +320,12 @@ public class LaticeApplicationWindow extends Application {
e.printStackTrace(); e.printStackTrace();
} }
confirmBtnClickedCount++; confirmBtnClickedCount++;
player.getRack().displayRack();
////// for the actual player //////
player.getRack().updateRack(); player.getRack().updateRack();
////// changing player ////// player.getRack().displayRack();
//making names colored in red to make the players know which player's round is //making names colored in red to make the players know which player's round is
if (confirmBtnClickedCount%2 == 0) { if (confirmBtnClickedCount%2 == 0) {
playerFX.setFillName(Constant.realColor.BLACK); playerFX.setFillName(Constant.realColor.BLACK);
@ -340,24 +339,22 @@ public class LaticeApplicationWindow extends Application {
playerFX.setFillName(Constant.realColor.RED); playerFX.setFillName(Constant.realColor.RED);
} }
////// for the next player ////// freeOrPayableTile = true;
isFreePlacement = true;
rackTileImage = player.getRack().createTileImage(); rackImage = player.getRack().createTileImage();
//Setting drag n drop on tiles setDragnDropOnRack(rackImage, player);
setDragnDropOnRack(rackTileImage, player);
setDragnDropOnRectangles(rect, board, referee, player); setDragnDropOnRectangles(rect, board, referee, player);
rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/); rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton);
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackImage);
} }
public void switchToGameFinishedScreen() throws IOException { private void switchToGameFinishedScreen() throws IOException {
//switching to game finished screen if the game finishes //switching to game finished screen if the game finishes
System.out.println("confirmBtnClickedCount : " + confirmBtnClickedCount); System.out.println("confirmBtnClickedCount : " + confirmBtnClickedCount);
if (confirmBtnClickedCount>=20) { if (confirmBtnClickedCount>=2) {
Parent loader = FXMLLoader.load(getClass().getResource("../view/GameFinishedScreen.fxml")); Parent loader = FXMLLoader.load(getClass().getResource("../view/GameFinishedScreen.fxml"));
Scene gameFinishedScreenScene = new Scene(loader, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT); Scene gameFinishedScreenScene = new Scene(loader, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
if (player1.getNumberOfTilesRemaining() < player2.getNumberOfTilesRemaining()) { if (player1.getNumberOfTilesRemaining() < player2.getNumberOfTilesRemaining()) {
@ -381,14 +378,14 @@ public class LaticeApplicationWindow extends Application {
}); });
//Rack with Image //With Image
rackTileImage = player.getRack().createTileImage(); rackImage = player.getRack().createTileImage();
//Adding lists to Arraylists //Adding lists to Arraylists
listRackTile = player.getRack().getListRackTile(); listRackTile = player.getRack().getListRackTile();
System.out.println(listRackTile); System.out.println(listRackTile);
listOfTilesInRack = player.getRack().getRackTileImage(); listRackImage = player.getRack().getRackTileImage();
System.out.println("listTileImge : " + listOfTilesInRack); System.out.println("listTileImge : " + listRackImage);
changeButton.setOnMouseClicked(new EventHandler<MouseEvent>() { changeButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@ -396,11 +393,7 @@ public class LaticeApplicationWindow extends Application {
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
////// for the actual player ////// ////// for the actual player //////
if (player.getScore() >= 2 || isFreePlacement) { if (player.getScore() > 1) {
if (!isFreePlacement) {
playerFX.setRemovePointsFromScore(player, 2);
}
System.out.println("Changing Rack"); System.out.println("Changing Rack");
confirmBtnClickedCount++; confirmBtnClickedCount++;
player.getRack().changeRack(); player.getRack().changeRack();
@ -422,39 +415,44 @@ public class LaticeApplicationWindow extends Application {
////// for the next player ////// ////// for the next player //////
isFreePlacement = true; freeOrPayableTile = true;
rackTileImage = player.getRack().createTileImage(); rackImage = player.getRack().createTileImage();
//Setting drag n drop on tiles //Setting drag n drop on tiles
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackImage, player);
rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/); rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton);
setDragnDropOnRectangles(rect, board, referee, player); setDragnDropOnRectangles(rect, board, referee, player);
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackImage);
}else { }else {
System.out.println("Not enough points to change the rack"); System.out.println("Not enough points to change the rack");
gameInfoLabel.setText("Error ! " + player.getName() + ", you haven't enough points to change your rack");
} }
} }
}); });
/*buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() { buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
gameInfoLabel.setText(player.getName() + ", you can now play another time !"); //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 !");
}*/
} }
});*/ });
rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/); rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton);
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackImage, player);
System.out.println(); System.out.println();
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackImage);
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -462,7 +460,7 @@ public class LaticeApplicationWindow extends Application {
System.out.println((indexTileClicked)); System.out.println((indexTileClicked));
ImagePattern imagePattern = new ImagePattern(listOfTilesInRack.get(getIndexTileClicked())); ImagePattern imagePattern = new ImagePattern(listRackImage.get(getIndexTileClicked()));
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -473,7 +471,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(); root.getChildren().clear();
//adding new childrens //adding new childrens
root.getChildren().addAll(infoPlayers, borderPane); root.getChildren().addAll(infoPlayers, borderPane);
@ -493,23 +491,26 @@ public class LaticeApplicationWindow extends Application {
rect[a][b].setOnDragEntered(new EventHandler<DragEvent>() { rect[a][b].setOnDragEntered(new EventHandler<DragEvent>() {
//if we are entering a rectangle
@Override @Override
public void handle(DragEvent arg0) { public void handle(DragEvent arg0) {
tileOnRect = rect[a][b].getFill(); 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 //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)); player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b));
if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == true ) { if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == true ) {
rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked))); rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked)));
} }
}
arg0.consume(); arg0.consume();
} }
}); });
rect[a][b].setOnDragExited(new EventHandler<DragEvent>() { rect[a][b].setOnDragExited(new EventHandler<DragEvent>() {
//if we are leaving a rectangle
@Override @Override
public void handle(DragEvent arg0) { public void handle(DragEvent arg0) {
if (arg0.isDropCompleted() == false) { if (arg0.isDropCompleted() == false) {
@ -522,8 +523,6 @@ public class LaticeApplicationWindow extends Application {
}); });
rect[a][b].setOnDragOver(new EventHandler <DragEvent>() { rect[a][b].setOnDragOver(new EventHandler <DragEvent>() {
//If we are traveling over a rectangle
@Override @Override
public void handle(DragEvent arg0) { public void handle(DragEvent arg0) {
@ -533,24 +532,26 @@ public class LaticeApplicationWindow extends Application {
}); });
rect[a][b].setOnDragDropped(new EventHandler<DragEvent>() { rect[a][b].setOnDragDropped(new EventHandler<DragEvent>() {
//If we are dropping a tile in a rectangle
@Override @Override
public void handle(DragEvent arg0) { 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))); rect[a][b].setFill(new ImagePattern(player.getRack().getRackTileImage().get(indexTileClicked)));
arg0.setDropCompleted(true);
gameInfoLabel.setText("");
//testing if player has enough points arg0.setDropCompleted(true);
if (referee.checkScoreToPlay(player, isFreePlacement) == false) { System.out.println("OK");
gameInfoLabel.setText("Error ! " + player.getName() + ", you haven't enough points to play another tile"); ErrorLabel.setText("");
if (referee.checkScoreToPlay(player, freeOrPayableTile) == false) {
ErrorLabel.setText("Error ! You haven't enough points to play another tile");
rect[a][b].setFill(tileOnRect); rect[a][b].setFill(tileOnRect);
}else { }else {
//testing if it's the free round
if (Constant.START) { if (Constant.START) {
if (rect[a][b] == rect[Constant.MOON_BOX_X][Constant.MOON_BOX_Y]) { if (rect[a][b] == rect[Constant.MOON_BOX_X][Constant.MOON_BOX_Y]) {
//if its's the center box (moon box) //if its's the center box (moon box)
@ -558,11 +559,11 @@ public class LaticeApplicationWindow extends Application {
board.setGridBoardTile(player.getRack().getListRackTile().get(indexTileClicked), a, b); board.setGridBoardTile(player.getRack().getListRackTile().get(indexTileClicked), a, b);
tileDropped = true; tileDropped = true;
isFreePlacement = false; freeOrPayableTile = false;
Constant.START = false; Constant.START = false;
}else { }else {
gameInfoLabel.setText("Error ! " + player.getName() + ", please place the first tile on the moon"); ErrorLabel.setText("Error ! Please place the first tile on the moon");
//removing all tiles from gameboard //removing all tiles from gameboard
rect[a][b].setFill(Constant.realColor.TRANSPARENT); rect[a][b].setFill(Constant.realColor.TRANSPARENT);
@ -572,12 +573,13 @@ public class LaticeApplicationWindow extends Application {
}else { }else {
//if it's not the first round of the game //if it's not the first round of the game
//putting the position of the gameboard's case on the tile from the rack System.out.println("OK3");
System.out.println("Règle effectué");
player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b)); player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b));
//verify if a tile is already placed //verify if a tile is already placed
if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == false ) { if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == false ) {
gameInfoLabel.setText("Error ! The tile can't be placed here because there is already a tile placed"); ErrorLabel.setText("Error ! The tile can't be placed here because there is already a tile placed");
rect[a][b].setFill(tileOnRect); rect[a][b].setFill(tileOnRect);
}else { }else {
@ -585,41 +587,37 @@ public class LaticeApplicationWindow extends Application {
int nbr = referee.neighborRule(board , player.getRack().getListRackTile().get(indexTileClicked)); int nbr = referee.neighborRule(board , player.getRack().getListRackTile().get(indexTileClicked));
if (nbr == 0) { if (nbr == 0) {
gameInfoLabel.setText("Error! The tile isn't placed next to another tile or there is no correspondance with the neighbor tiles!"); ErrorLabel.setText("Error ! The tile isn't place next to another tile or there is no correspondance with the neighbor tiles !!");
rect[a][b].setFill(Constant.realColor.TRANSPARENT); rect[a][b].setFill(Constant.realColor.TRANSPARENT);
}else { }else {
if (isFreePlacement == false) { if (freeOrPayableTile == false) {
playerFX.setRemovePointsFromScore(player, 2); playerFX.setDiffScore(player, 2);
} }
if (nbr == 2) { if (nbr == 2) {
System.out.println("Vous avez gagné 1 point"); System.out.println("Vous avez gagné 1 point");
gameInfoLabel.setText(player.getName() + ", you won 1 point"); playerFX.setAddScore(player, 1);
playerFX.setAddPointsToScore(player, 1);
}else if (nbr == 3) { }else if (nbr == 3) {
System.out.println("Vous avez gagné 2 points"); System.out.println("Vous avez gagné 2 points");
gameInfoLabel.setText(player.getName() + ", you won 2 points"); playerFX.setAddScore(player, 2);
playerFX.setAddPointsToScore(player, 2);
}else if (nbr == 4) { }else if (nbr == 4) {
System.out.println("Vous avez gagné 4 points"); System.out.println("Vous avez gagné 4 points");
gameInfoLabel.setText(player.getName() + ", you won 4 points"); playerFX.setAddScore(player, 4);
playerFX.setAddPointsToScore(player, 4);
} }
board.setGridBoardTile(player.getRack().getListRackTile().get(getIndexTileClicked()), a, b); board.setGridBoardTile(player.getRack().getListRackTile().get(getIndexTileClicked()), a, b);
tileDropped = true; tileDropped = true;
isFreePlacement = false; freeOrPayableTile = false;
System.out.println("tuile posé!"); System.out.println("tuile posé!");
//Sun rule //Sun rule
if (referee.sunRule(board, player.getRack().getListRackTile().get(indexTileClicked))) { if (referee.sunRule(board, player.getRack().getListRackTile().get(indexTileClicked))) {
System.out.println("Vous avez gagné 2 points en mettant votre tuile sur un soleil"); System.out.println("Vous avez gagné 2 points en mettant votre tuile sur un soleil");
gameInfoLabel.setText("Wow! " + player.getName() + ", you won 2 points by placing a tile on a sun !"); playerFX.setAddScore(player, 2);
playerFX.setAddPointsToScore(player, 2);
} }
} }
@ -637,12 +635,18 @@ public class LaticeApplicationWindow extends Application {
} }
} }
} }
//-------------------------------------------------------------------------------
private void setDragnDropOnRack(HBox rackBox, Player player) { private void setDragnDropOnRack(HBox rackBox, Player player) {
//Setting drag n drop on tiles //Setting drag n drop on tiles
for (int i=0; i< player.getRack().getRackTileImage().size(); i++) { for (int i=0; i< player.getRack().getRackTileImage().size(); i++) {
int a = i; int a = i;
System.out.println(a);
//HBox t = rackBox.getChildren().indexOf(rack);
rackBox.getChildren().get(a).setOnDragDetected(new EventHandler<MouseEvent>() { rackBox.getChildren().get(a).setOnDragDetected(new EventHandler<MouseEvent>() {
@Override @Override
@ -664,13 +668,14 @@ public class LaticeApplicationWindow extends Application {
public void handle(DragEvent arg0) { public void handle(DragEvent arg0) {
if (tileDropped) { if (tileDropped) {
player.getRack().getListRackTile().remove(a); player.getRack().getListRackTile().remove(a);
rackTileImage = player.getRack().createTileImage(); rackImage = player.getRack().createTileImage();
//Setting drag n drop on tiles //Setting drag n drop on tiles
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackImage, player);
rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/); rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton);
borderPane.setBottom(rackTileImage); //setDragnDropOnRectangles(rect, board, referee, player);
borderPane.setBottom(rackImage);
tileDropped = false; tileDropped = false;
playerFX.setTilesRemaining(player); playerFX.setTilesRemaining(player);
} }
@ -686,6 +691,10 @@ public class LaticeApplicationWindow extends Application {
return rootLayout; return rootLayout;
} }
public static String getNameWinner() {
return nameWinner.getText();
}
//getter to get the index of the mouse clicked tile //getter to get the index of the mouse clicked tile
public static int getIndexTileClicked() { public static int getIndexTileClicked() {
return indexTileClicked; return indexTileClicked;

View File

@ -18,9 +18,7 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.web.WebView;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
@ -70,30 +68,40 @@ public class MainScreenController extends LaticeApplicationWindow{
// Event Listener on Rectangle[#rulesButton].onMouseClicked // Event Listener on Rectangle[#rulesButton].onMouseClicked
@FXML @FXML
public void rulesButtonClicked(MouseEvent event) { public void rulesButtonClicked(MouseEvent event) {
//Adding the Web View of the official Latice Rules
System.out.println("rulesButtonClicked"); 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) // New window (Stage)
Stage newWindow = new Stage(); Stage newWindow = new Stage();
newWindow.setTitle("Règles du jeu Latice"); newWindow.setTitle("Règles du jeu Latice");
newWindow.setScene(secondScene);
WebView webView = new WebView(); // Specifies the modality for new window
webView.getEngine().load("https://latice.com/how/#rules-objective"); newWindow.initModality(Modality.WINDOW_MODAL);
VBox videoContainer = new VBox(webView);
// Specifies the owner window
newWindow.initOwner(primaryStage);
// Set position of window
newWindow.setX(primaryStage.getX() + 300);
newWindow.setY(primaryStage.getY() + 175);
newWindow.setScene(new Scene(videoContainer, 1100, 680));
newWindow.show(); newWindow.show();
} }
// Event Listener on Rectangle[#exitButton].onMouseClicked // Event Listener on Rectangle[#exitButton].onMouseClicked
@FXML @FXML
public void exitButtonClicked(MouseEvent event) { public void exitButtonClicked(MouseEvent event) {
//shut down the Platform
System.out.println("exitButtonClicked"); System.out.println("exitButtonClicked");
Platform.exit(); Platform.exit();
} }
public void playerNamesInput(MouseEvent event) throws IOException { public void playerNamesInput(MouseEvent event) throws IOException {
//loading the stage to enter player names
Parent loader = FXMLLoader.load(getClass().getResource("../view/PlayerNameInput.fxml")); Parent loader = FXMLLoader.load(getClass().getResource("../view/PlayerNameInput.fxml"));
Scene nameInputScene = new Scene(loader, 600, 300); Scene nameInputScene = new Scene(loader, 600, 300);
Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
@ -122,6 +130,34 @@ public class MainScreenController extends LaticeApplicationWindow{
} }
/*public void startGame(Stage stage) {
parentStackPane = parentStackPaneStock;
StackPane root = getRootLayout();
root.translateYProperty().set(stage.getHeight());
System.out.println(parentStackPane);
System.out.println(parentStackPaneStock);
parentStackPane.getChildren().add(root);
players = PlayerFX.displayPlayers(parentStackPane,player1, player2);
root.getChildren().addAll(players,LaticeApplicationWindow.borderPane);
//parameters of the animation
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN);
KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
timeline.getKeyFrames().add(kf);
//when the animation is finished we're removing the main screen
timeline.setOnFinished(t -> {
parentStackPane.getChildren().remove(menuBorderPane);
});
timeline.play();
//Règles
}*/
public StackPane getParentStackPane() { public StackPane getParentStackPane() {
System.out.println(parentStackPane); System.out.println(parentStackPane);
return parentStackPane; return parentStackPane;
@ -139,6 +175,8 @@ public class MainScreenController extends LaticeApplicationWindow{
for (Color color : Color.values()) { for (Color color : Color.values()) {
for (Shape shape : Shape.values()) { for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape); Tile tile = new Tile(color, shape);
//System.out.println(color.getStringColor() + shape.getStringShape()+ ".png");
listOfTile.add(tile); listOfTile.add(tile);
} }

View File

@ -47,7 +47,6 @@ public class PlayerNameInputController {
public void validBtnClicked(MouseEvent event) { public void validBtnClicked(MouseEvent event) {
System.out.println("valid Button Clicked"); System.out.println("valid Button Clicked");
//Verifying if player's names are correct
if(nomJoueur1.getText().length() < 3 || nomJoueur1.getText().length() > 16) { if(nomJoueur1.getText().length() < 3 || nomJoueur1.getText().length() > 16) {
label1.setVisible(true); label1.setVisible(true);
} }
@ -60,8 +59,8 @@ public class PlayerNameInputController {
//setting player names //setting player names
String name1 = nomJoueur1.getText(); String name1 = nomJoueur1.getText();
String name2 = nomJoueur2.getText(); String name2 = nomJoueur2.getText();
System.out.println("nom des joueurs :");
System.out.println(nomJoueur1.getText()); System.out.println(nomJoueur1.getText());
System.out.println("nom des joueurs");
System.out.println(nomJoueur2.getText()); System.out.println(nomJoueur2.getText());
namePlayer1 = name1; namePlayer1 = name1;
namePlayer2 = name2; namePlayer2 = name2;
@ -72,7 +71,7 @@ public class PlayerNameInputController {
mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); mainScreenController.player1 = mainScreenController.instanciatePlayer(name1);
mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); mainScreenController.player2 = mainScreenController.instanciatePlayer(name2);
//Starting game //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2);
mainScreenController.startGameInstruction(false); mainScreenController.startGameInstruction(false);
} }
} }

View File

@ -23,7 +23,7 @@ public class Constant {
public static final int BOX_WIDTH = 52; public static final int BOX_WIDTH = 52;
public static final int ACTION_BUTTONS_WIDTH = 170; public static final int ACTION_BUTTONS_WIDTH = 120;
public static final int ACTION_BUTTONS_HEIGHT = 45; public static final int ACTION_BUTTONS_HEIGHT = 45;

View File

@ -24,6 +24,19 @@ public class Player {
this(name, new Score(), deck, new Rack(deck)); this(name, new Score(), deck, new Rack(deck));
} }
/*public Player(Score score, Deck deck, Rack rack) {
this(namePlayer,score,deck,rack);
//Demande le nom du joueur
Scanner enterPlayerName = new Scanner(System.in);
System.out.println("Veuilez entrer votre nom :");
String namePlayer = enterPlayerName.next();
}*/
public String getName() { public String getName() {
return this.name; return this.name;
} }
@ -40,13 +53,13 @@ public class Player {
return this.deck.getListTile().size() + this.rack.getListRackTile().size(); return this.deck.getListTile().size() + this.rack.getListRackTile().size();
} }
public Integer addPointsToScore(Integer value) { public Integer addScore(Integer value) {
int newScore = this.score.getScore()+value; int newScore = this.score.getScore()+value;
this.score.setScore(newScore); this.score.setScore(newScore);
return this.score.getScore(); return this.score.getScore();
} }
public Integer removePointsFromScore(Integer value) { public Integer diffScore(Integer value) {
int newScore = this.score.getScore()-value; int newScore = this.score.getScore()-value;
this.score.setScore(newScore); this.score.setScore(newScore);
return this.score.getScore(); return this.score.getScore();
@ -63,7 +76,7 @@ public class Player {
} }
System.out.print("Quelle tuile voulez-vous jouez ? "); System.out.print("Quel tuile voulez-vous jouez ? ");
this.rack.displayRack(); this.rack.displayRack();
Integer idTileToPlay = Integer.parseInt(play.next())-1; Integer idTileToPlay = Integer.parseInt(play.next())-1;
Tile tileToPlay = this.rack.getListRackTile().get(idTileToPlay); Tile tileToPlay = this.rack.getListRackTile().get(idTileToPlay);
@ -75,6 +88,12 @@ public class Player {
tileToPlay.setPosition(new Position(row, column)); tileToPlay.setPosition(new Position(row, column));
return tileToPlay; return tileToPlay;
//.setGridBoard(" "+tileToPlay.getShapeConsole()+tileToPlay.getColorConsole()+" ", row, column);
//this.rack.removeTile(tileToPlay);
//board.displayGameBoard();
//this.rack.updateRack();
} }

View File

@ -6,9 +6,10 @@ import java.util.regex.Pattern;
import latice.model.console.GameBoard; import latice.model.console.GameBoard;
public class Rules { public class Rules {
//private static boolean START = true;
public Rules() { public Rules() {
// TODO Auto-generated constructor stub
} }
public Boolean moonRule(GameBoard board, Tile tile) { public Boolean moonRule(GameBoard board, Tile tile) {
@ -110,38 +111,32 @@ public class Rules {
return this.moonRule(board, tile); return this.moonRule(board, tile);
}else { }else {
System.out.println("-----------------------------"); System.out.println("-----------------------------");
if (this.checkPositionRule(board, tile) == false ) { if (this.sunRule(board, tile)){
System.out.println("Erreur ! la tuile ne peut pas être placé ici car il y a déjà une tuile placé"); player.addScore(2);
return false; }
}else {
int nbr = this.neighborRule(board, tile); int nbr = this.neighborRule(board, tile);
if (nbr == 0) { if (nbr == 0) {
System.out.println("Erreur ! L'emplacement où est posé la tuile n'a pas de voisin ou il n'y a pas de correspondance avec les voisins !"); System.out.println("l'emplacement où est posé la tuile n'a pas de voisin ou il n'y a pas de correspondance avec les voisins !");
return false; return false;
}else { }else {
if (nbr == 2) { if (nbr == 2) {
System.out.println("Vous avez gagné 1 point"); System.out.println("Vous avez gagné 1 point");
player.addPointsToScore(1); player.addScore(1);
}else if (nbr == 3) { }else if (nbr == 3) {
System.out.println("Vous avez gagné 2 points"); System.out.println("Vous avez gagné 2 points");
player.addPointsToScore(2); player.addScore(2);
}else if (nbr == 4) { }else if (nbr == 4) {
System.out.println("Vous avez gagné 4 points"); System.out.println("Vous avez gagné 4 points");
player.addPointsToScore(4); player.addScore(4);
}
if (this.sunRule(board, tile)){
player.addPointsToScore(2);
}
} }
return true; return true;
}
}
}
} }
} }
}

View File

@ -17,7 +17,7 @@ public class GameBoard {
for (int i = 0; i < DIMENSION; i++) { for (int i = 0; i < DIMENSION; i++) {
for (int j = 0; j < DIMENSION; j++) { for (int j = 0; j < DIMENSION; j++) {
System.out.print("|");
if (i == 4 && j == 4) { //Affiche la lune au centre du plateau if (i == 4 && j == 4) { //Affiche la lune au centre du plateau
this.gridBoard[i][j] = MOON; this.gridBoard[i][j] = MOON;
@ -39,40 +39,42 @@ public class GameBoard {
this.gridBoard[i][j] = BLUE; this.gridBoard[i][j] = BLUE;
} }
if (j == 8) {
System.out.println("|");
}
} }
} }
} }
public void displayGameBoard() { public void displayGameBoard() {
System.out.println(" 1. 2. 3. 4. 5. 6. 7. 8. 9."); System.out.println(" 1. 2. 3. 4. 5. 6. 7. 8. 9.");
System.out.println(" ____ ____ ____ ____ ____ ____ ____ ____ ____ "); System.out.println(" +----+----+----+----+----+----+----+----+----+");
for (int i = 0; i < DIMENSION; i++) { for (int i = 0; i < DIMENSION; i++) {
System.out.println(" | | | | | | | | | |");
System.out.print(i+1 + ". "); System.out.print(i+1 + ". ");
for (int j = 0; j < DIMENSION; j++) { for (int j = 0; j < DIMENSION; j++) {
System.out.print("|"); System.out.print("|");
if (i == 4 && j == 4) { //display moon in the center of the board if (i == 4 && j == 4) { //Affiche la lune au centre du plateau
if (this.gridBoardTile[i][j] == null) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if (i == j && (i <= 2 || i >= 6)) { //display the diagonal ('\') of the sun }else if (i == j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('\') de soleil
if (this.gridBoardTile[i][j] == null) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if (i == DIMENSION-1-j && (i <= 2 || i >= 6)) { //display the diagonal ('/') of the sun }else if (i == DIMENSION-1-j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('/') de soleil
if (this.gridBoardTile[i][j] == null) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if ( ((i == 0 || i == 8)&& j == 4) || (i== 4 && (j == 0 || j == 8)) ) {//display the suns at the middle of each side ('+') }else if ( ((i == 0 || i == 8)&& j == 4) || (i== 4 && (j == 0 || j == 8)) ) {//Affiche les soleils au mileu de chaque coté ('+')
if (this.gridBoardTile[i][j] == null) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
@ -89,7 +91,7 @@ public class GameBoard {
if (j == 8) { if (j == 8) {
System.out.println("|"); System.out.println("|");
System.out.println(" |____|____|____|____|____|____|____|____|____|"); System.out.println(" +----+----+----+----+----+----+----+----+----+");
} }

View File

@ -20,7 +20,7 @@ public class Rack {
Tile tile; Tile tile;
//System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs");
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
int index = (int)(Math.random()*(((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min); int index = (int)(Math.random()*(((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min);
@ -29,9 +29,15 @@ public class Rack {
this.listRackTile.add(tile); this.listRackTile.add(tile);
this.deck.getListTile().remove(index); this.deck.getListTile().remove(index);
} }
//System.out.println("Il y a dans le rack : " + this.listRackTile.size() + " valeurs"); System.out.println("Il y a dans le rack : " + this.listRackTile.size() + " valeurs");
} }
public ArrayList<Tile> getListRackTile() { public ArrayList<Tile> getListRackTile() {
@ -46,7 +52,7 @@ public class Rack {
public void updateRack() { public void updateRack() {
Tile tile; Tile tile;
//System.out.println("nomdre de tuile dans le rack : " + this.listRackTile.size()); System.out.println("nomdre de tuile dans le rack : " + this.listRackTile.size());
for (int i = this.listRackTile.size(); i < 5 ; i++) { for (int i = this.listRackTile.size(); i < 5 ; i++) {
int index = (int)(Math.random()*( ((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min); int index = (int)(Math.random()*( ((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min);
@ -158,5 +164,11 @@ public class Rack {
} }
// TODO add method(s) javafx
} }

View File

@ -0,0 +1,264 @@
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<Tile> listRackTile;
ArrayList<Image> listTileImage;
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
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<MouseEvent>() {
@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<Player> 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<MouseEvent>() {
@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<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
}
});
}
}
}

View File

@ -19,8 +19,14 @@ public class PlayerFX {
private VBox infoPlayer; private VBox infoPlayer;
public VBox displayPlayers(StackPane root, Player player) { public VBox displayPlayers(StackPane root, Player player) {
//-------------- display name, score and deck of each player ---------------// //###################### 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 ) {
this.infoPlayer = new VBox(); this.infoPlayer = new VBox();
this.name = new Text(); this.name = new Text();
@ -36,27 +42,28 @@ public class PlayerFX {
this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles); this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles);
this.infoPlayer.setSpacing(5); this.infoPlayer.setSpacing(5);
//players.getChildren().add(infoPlayer);
//players.setMargin(infoPlayer, new Insets(50,0,0,55));
//}
//players.setSpacing(850);
return this.infoPlayer; return this.infoPlayer;
} }
//setting the player's nickname who plays in red
public void setFillName(javafx.scene.paint.Color color) { public void setFillName(javafx.scene.paint.Color color) {
name.setFill(color); name.setFill(color);
} }
//adding points to player public void setAddScore(Player player, Integer score) {
public void setAddPointsToScore(Player player, Integer score) { player.addScore(score);
player.addPointsToScore(score);
this.score.setText("Score : " + player.getScore()); this.score.setText("Score : " + player.getScore());
} }
//Removing points from player public void setDiffScore(Player player, Integer score) {
public void setRemovePointsFromScore(Player player, Integer score) { player.diffScore(score);
player.removePointsFromScore(score);
this.score.setText("Score : " + player.getScore()); this.score.setText("Score : " + player.getScore());
} }
//Setting the tiles remaining
public void setTilesRemaining(Player player) { public void setTilesRemaining(Player player) {
this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining()); this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining());
} }

View File

@ -13,9 +13,9 @@
<image> <image>
<Image url="@/gameFinishedImage.png" /> <Image url="@/gameFinishedImage.png" />
</image></ImageView> </image></ImageView>
<Label fx:id="nameWinner" alignment="CENTER_RIGHT" layoutX="274.0" layoutY="236.0" prefHeight="51.0" prefWidth="488.0" textAlignment="CENTER" textFill="WHITE"> <Label fx:id="nameWinner" alignment="CENTER_RIGHT" layoutX="453.0" layoutY="247.0" prefHeight="22.0" prefWidth="300.0" textAlignment="CENTER">
<font> <font>
<Font name="Verdana" size="40.0" /> <Font name="Bell MT" size="40.0" />
</font></Label> </font></Label>
<Button fx:id="quitBtn" layoutX="753.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#quitBtnClicked" prefHeight="140.0" prefWidth="380.0" style="-fx-background-color: transparent;" textFill="TRANSPARENT" /> <Button fx:id="quitBtn" layoutX="753.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#quitBtnClicked" prefHeight="140.0" prefWidth="380.0" style="-fx-background-color: transparent;" textFill="TRANSPARENT" />
<Button fx:id="replayBtn" layoutX="175.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#replayBtnClicked" prefHeight="140.0" prefWidth="380.0" style="-fx-background-color: transparent;" textFill="TRANSPARENT" /> <Button fx:id="replayBtn" layoutX="175.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#replayBtnClicked" prefHeight="140.0" prefWidth="380.0" style="-fx-background-color: transparent;" textFill="TRANSPARENT" />

View File

@ -7,17 +7,12 @@ import java.util.ArrayList;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javafx.application.Application;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import latice.model.Color; import latice.model.Color;
import latice.model.Player; import latice.model.Player;
import latice.model.Position; import latice.model.Position;
import latice.model.Rules;
import latice.model.Shape; import latice.model.Shape;
import latice.model.Tile; import latice.model.Tile;
import latice.model.console.Deck; import latice.model.console.Deck;
import latice.model.console.GameBoard;
import latice.model.console.Rack; import latice.model.console.Rack;
import latice.model.console.Score; import latice.model.console.Score;
@ -207,276 +202,26 @@ class LaticeTest {
assertEquals(0, player.getScore()); assertEquals(0, player.getScore());
assertEquals(rack, player.getRack()); assertEquals(rack, player.getRack());
player.addPointsToScore(2); player.addScore(2);
assertEquals(2, player.getScore()); assertEquals(2, player.getScore());
player.removePointsFromScore(1); player.diffScore(1);
assertEquals(1, player.getScore()); assertEquals(1, player.getScore());
} }
@Test
void should_create_tile_image() { /*@Test
void () {
//Arrange //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 //Act
//Assert //Assert
//assertEquals(5, player.getRack().createTileImage().getChildren().size());
} }*/
@Test
void should_get_gridboard() {
GameBoard gameBoard = new GameBoard();
String[][] gridBoard = gameBoard.getGridBoard();
assertEquals(9, gridBoard.length);
}
@Test
void should_set_gridboard() {
GameBoard gameBoard = new GameBoard();
gameBoard.setGridBoard("SUN", 0, 0);
String[][] gridBoard = gameBoard.getGridBoard();
assertEquals("SUN", gridBoard[0][0]);
}
@Test
void should_get_gridboard_tile() {
GameBoard gameBoard = new GameBoard();
Tile[][] tiles = gameBoard.getGridBoardTile();
assertEquals(9, tiles.length);
}
@Test
void should_set_gridboard_tile() {
//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);
GameBoard gameBoard = new GameBoard();
Tile[][] tiles = gameBoard.getGridBoardTile();
System.out.println("tiles\n\n" + tiles[0][0]);
gameBoard.setGridBoardTile(player.getRack().getListRackTile().get(0), 1, 0);
assertEquals(player.getRack().getListRackTile().get(0), gameBoard.getGridBoardTile()[1][0]);
}
@Test
void should_display_list_tile() {
//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);
deck.displayListTile();
}
@Test
void should_return_rackTileImage() {
//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);
assertEquals(0, rack.getRackTileImage().size());
}
@Test
void should_verfy_moon_placement() {
//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);
rack.getListRackTile().get(0).setPosition(new Position(4, 4));
rack.getListRackTile().get(1).setPosition(new Position(3, 4));
GameBoard gameBoard = new GameBoard();
Rules referee = new Rules();
assertEquals(true, referee.moonRule(gameBoard, rack.getListRackTile().get(0)));
assertEquals(false, referee.moonRule(gameBoard, rack.getListRackTile().get(1)));
}
@Test
void should_verfy_sun_placement() {
//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);
rack.getListRackTile().get(0).setPosition(new Position(0, 0));
rack.getListRackTile().get(1).setPosition(new Position(1,0));
GameBoard gameBoard = new GameBoard();
Rules referee = new Rules();
assertEquals(true, referee.sunRule(gameBoard, rack.getListRackTile().get(0)));
assertEquals(false, referee.sunRule(gameBoard, rack.getListRackTile().get(1)));
}
@Test
void should_test_if_we_have_enough_points_to_play_a_tile() {
//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);
GameBoard gameBoard = new GameBoard();
Rules referee = new Rules();
assertEquals(false, referee.checkScoreToPlay(player, false));
assertEquals(true, referee.checkScoreToPlay(player, true));
}
@Test
void should_test_if_a_box_is_empty() {
//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);
GameBoard gameBoard = new GameBoard();
Rules referee = new Rules();
player.getRack().getListRackTile().get(0).setPosition(new Position(0, 0));
player.getRack().getListRackTile().get(1).setPosition(new Position(0, 0));
assertEquals(true, referee.checkPositionRule(gameBoard, player.getRack().getListRackTile().get(0)));
assertEquals(true, referee.checkPositionRule(gameBoard, player.getRack().getListRackTile().get(1)));
}
@Test
void should_test_neighbor_rule() {
//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);
GameBoard gameBoard = new GameBoard();
Rules referee = new Rules();
player.getRack().getListRackTile().get(0).setPosition(new Position(0, 0));
player.getRack().getListRackTile().get(1).setPosition(new Position(0, 1));
assertEquals(0, referee.neighborRule(gameBoard, player.getRack().getListRackTile().get(1)));
}
} }