Compare commits

..

12 Commits

Author SHA1 Message Date
Mathis ccb61b5ef8 UPDATE "change Rack (2 points)" -> "change Rack" 2022-06-07 15:33:55 +02:00
Mathis e81a73d554 UPDATE display of the gameboard 2022-06-07 14:56:26 +02:00
Cemal Odabasioglu f832d54911 added tests and few bugfixes 2022-06-07 14:35:48 +02:00
Cemal Odabasioglu 38c6ea073b added free change rack in free round 2022-06-07 11:05:31 +02:00
Mathis 6f3179ee91 little UPDATE LaticeApplicationWindow, buttons "Confirm" -> "End Turn"
and "Change Rack (2 points)" -> "Change Rack (3 points)"
2022-06-06 23:57:18 +02:00
Mathis 2ae745c638 cleaned the source code 2 2022-06-06 23:55:02 +02:00
Cemal Odabasioglu 8aa26ca8de added forgotten class 2022-06-06 22:48:02 +02:00
Cemal Odabasioglu 14a0045859 Cleaned the source code 2022-06-06 22:47:39 +02:00
Odabasioglu Cemal 2a73cfb775 Merge branch 'bugfix_players_when_replay' into 'master'
UPDATE Player, LaticeApplicationWindow and LaticeApplicationConsole

See merge request odabasioglu1/latice!11
2022-06-06 13:31:07 +00:00
Odabasioglu Cemal 5789fab5fe Merge branch 'master' into 'bugfix_players_when_replay'
# Conflicts:
#   src/main/java/latice/application/LaticeApplicationWindow.java
2022-06-06 13:31:02 +00:00
Cemal Odabasioglu 5c36959b5a add laticeApp forgotten 2022-06-05 23:46:35 +02:00
Cemal Odabasioglu 89e1461810 added replay function and clean code 2022-06-05 23:46:06 +02:00
13 changed files with 455 additions and 603 deletions

View File

@ -20,13 +20,10 @@ public class LaticeApplicationConsole {
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
//System.out.println("Hello Latice !");
/*
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);
@ -35,85 +32,20 @@ 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("-----------------");
Deck deck1 = 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 player2 = new Player("player2", deck2);
System.out.println("-----------------");
GameBoard board = new GameBoard();
board.displayGameBoard();
System.out.println(Objects.equals(board.getGridBoard()[1][0], Tile.class));
Scanner play = new Scanner(System.in);
Player player;
Boolean round;
@ -137,15 +69,17 @@ public class LaticeApplicationConsole {
while (round) {
player.getRack().displayRack();
System.out.println("Vous avez " + player.getScore() +" points, que voulez-vous faire ?\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\n"
+ " 1. Jouer une Tuile\n"
+ " 2. Acheter une action supplémentaire(coûte 2 points)\n"
+ " 3. Changer le Rack et passer(coûte 3 points)\n"
+ " 4. Passer\n");
System.out.print("Choix : ");
int choiceMenu = Integer.parseInt(play.next());
switch(choiceMenu) {
case 1: if (freeTile) {
freeTile = false;
Boolean rulesCheck = false;
while (rulesCheck == false) {
@ -165,17 +99,25 @@ public class LaticeApplicationConsole {
player.getRack().removeTile(tile);
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;
case 2:
if (player.getScore()>=3) {
//Donner une action supplémentaire et enlever 3 points au joueur
player.Play(play, board, 0);
player.diffScore(2);
if (freeTile) {
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 !");
}else {
System.out.println("Il vous faut 2 points pour acheter une nouvelle action !");
if (player.getScore()>=2) {
//Buy another action and remove 2 points from score
player.Play(play, board, 0);
player.removePointsFromScore(2);
freeTile = true;
}else {
System.out.println("Il vous faut 2 points pour acheter une nouvelle action !");
}
}
break;

View File

@ -63,8 +63,8 @@ public class LaticeApplicationWindow extends Application {
//lists for tiles
ArrayList<Tile> listRackTile;
ArrayList<Image> listRackImage;
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
ArrayList<Image> listOfTilesInRack;
//ArrayList<Tile> listOfTile = new ArrayList<Tile>();
static StackPane rootLayout;
public static int indexTileClicked;
@ -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
@ -260,21 +260,21 @@ public class LaticeApplicationWindow extends Application {
//Creating tiles
for (Color color : Color.values()) {
/*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("-----------------");
System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile);
System.out.println("-----------------");
Rack rack = new Rack(deck);
System.out.println("-----------------");
System.out.println("-----------------");*/
//Player
@ -286,7 +286,7 @@ public class LaticeApplicationWindow extends Application {
//Confirm Button
Image checkMark = new Image("checkMark.png");
ImageView checkMarkView = new ImageView(checkMark);
confirmButton = new Button("Confirm", checkMarkView);
confirmButton = new Button("End Turn", checkMarkView);
confirmButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH);
confirmButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
@ -299,11 +299,11 @@ public class LaticeApplicationWindow extends Application {
changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
//Buy another action Button
Image buyActionImage = new Image("buyAction.png");
/*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);
buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);*/
confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
//confirming the end of the round and switching round
@ -320,12 +320,13 @@ public class LaticeApplicationWindow extends Application {
e.printStackTrace();
}
confirmBtnClickedCount++;
player.getRack().displayRack();
////// for the actual player //////
player.getRack().updateRack();
player.getRack().displayRack();
////// changing player //////
//making names colored in red to make the players know which player's round is
if (confirmBtnClickedCount%2 == 0) {
playerFX.setFillName(Constant.realColor.BLACK);
@ -339,22 +340,24 @@ public class LaticeApplicationWindow extends Application {
playerFX.setFillName(Constant.realColor.RED);
}
freeOrPayableTile = true;
////// for the next player //////
isFreePlacement = true;
rackImage = player.getRack().createTileImage();
setDragnDropOnRack(rackImage, player);
rackTileImage = player.getRack().createTileImage();
//Setting drag n drop on tiles
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);
}
private void switchToGameFinishedScreen() throws IOException {
public void switchToGameFinishedScreen() throws IOException {
//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()) {
@ -378,14 +381,14 @@ public class LaticeApplicationWindow extends Application {
});
//With Image
rackImage = player.getRack().createTileImage();
//Rack with Image
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<MouseEvent>() {
@ -393,7 +396,11 @@ public class LaticeApplicationWindow extends Application {
public void handle(MouseEvent arg0) {
////// for the actual player //////
if (player.getScore() > 1) {
if (player.getScore() >= 2 || isFreePlacement) {
if (!isFreePlacement) {
playerFX.setRemovePointsFromScore(player, 2);
}
System.out.println("Changing Rack");
confirmBtnClickedCount++;
player.getRack().changeRack();
@ -415,44 +422,39 @@ 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");
}
}
});
buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
/*buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@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 +462,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 +473,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);
@ -491,26 +493,23 @@ public class LaticeApplicationWindow extends Application {
rect[a][b].setOnDragEntered(new EventHandler<DragEvent>() {
//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<DragEvent>() {
//if we are leaving a rectangle
@Override
public void handle(DragEvent arg0) {
if (arg0.isDropCompleted() == false) {
@ -523,6 +522,8 @@ public class LaticeApplicationWindow extends Application {
});
rect[a][b].setOnDragOver(new EventHandler <DragEvent>() {
//If we are traveling over a rectangle
@Override
public void handle(DragEvent arg0) {
@ -532,26 +533,24 @@ public class LaticeApplicationWindow extends Application {
});
rect[a][b].setOnDragDropped(new EventHandler<DragEvent>() {
//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 +558,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 +572,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é");
//putting the position of the gameboard's case on 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 +585,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 +637,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<MouseEvent>() {
@Override
@ -668,14 +664,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 +686,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;

View File

@ -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;
@ -68,40 +70,30 @@ public class MainScreenController extends LaticeApplicationWindow{
// Event Listener on Rectangle[#rulesButton].onMouseClicked
@FXML
public void rulesButtonClicked(MouseEvent event) {
//Adding the Web View of the official Latice Rules
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);
WebView webView = new WebView();
webView.getEngine().load("https://latice.com/how/#rules-objective");
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.show();
newWindow.setScene(new Scene(videoContainer, 1100, 680));
newWindow.show();
}
// Event Listener on Rectangle[#exitButton].onMouseClicked
@FXML
public void exitButtonClicked(MouseEvent event) {
//shut down the Platform
System.out.println("exitButtonClicked");
Platform.exit();
}
public void playerNamesInput(MouseEvent event) throws IOException {
//loading the stage to enter player names
Parent loader = FXMLLoader.load(getClass().getResource("../view/PlayerNameInput.fxml"));
Scene nameInputScene = new Scene(loader, 600, 300);
Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
@ -130,34 +122,6 @@ 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() {
System.out.println(parentStackPane);
return parentStackPane;
@ -175,8 +139,6 @@ public class MainScreenController extends LaticeApplicationWindow{
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);
}

View File

@ -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);
}
@ -59,8 +60,8 @@ public class PlayerNameInputController {
//setting player names
String name1 = nomJoueur1.getText();
String name2 = nomJoueur2.getText();
System.out.println("nom des joueurs :");
System.out.println(nomJoueur1.getText());
System.out.println("nom des joueurs");
System.out.println(nomJoueur2.getText());
namePlayer1 = name1;
namePlayer2 = name2;
@ -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);
}
}

View File

@ -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;

View File

@ -24,19 +24,6 @@ public class Player {
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() {
return this.name;
}
@ -53,13 +40,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();
@ -76,7 +63,7 @@ public class Player {
}
System.out.print("Quel tuile voulez-vous jouez ? ");
System.out.print("Quelle tuile voulez-vous jouez ? ");
this.rack.displayRack();
Integer idTileToPlay = Integer.parseInt(play.next())-1;
Tile tileToPlay = this.rack.getListRackTile().get(idTileToPlay);
@ -88,12 +75,6 @@ public class Player {
tileToPlay.setPosition(new Position(row, column));
return tileToPlay;
//.setGridBoard(" "+tileToPlay.getShapeConsole()+tileToPlay.getColorConsole()+" ", row, column);
//this.rack.removeTile(tileToPlay);
//board.displayGameBoard();
//this.rack.updateRack();
}

View File

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

View File

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

View File

@ -20,7 +20,7 @@ public class Rack {
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++) {
int index = (int)(Math.random()*(((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min);
@ -29,15 +29,9 @@ public class Rack {
this.listRackTile.add(tile);
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() {
@ -52,7 +46,7 @@ public class Rack {
public void updateRack() {
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++) {
int index = (int)(Math.random()*( ((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min);
@ -164,11 +158,5 @@ public class Rack {
}
// TODO add method(s) javafx
}

View File

@ -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<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,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 ---------------//
//ArrayList<Player> allPlayers = new ArrayList<>();
//allPlayers.add(player1);
//allPlayers.add(player2);
this.infoPlayer = new VBox();
//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.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.score = new Text();
this.score.setText("Score : " + player.getScore());
this.nbrOfTiles = new Text();
this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining());
this.nbrOfTiles = new Text();
this.nbrOfTiles.setText("Tuiles restantes : " + player.getNumberOfTilesRemaining());
this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles);
this.infoPlayer.setSpacing(5);
this.infoPlayer.getChildren().addAll(name, score, nbrOfTiles);
this.infoPlayer.setSpacing(5);
//players.getChildren().add(infoPlayer);
//players.setMargin(infoPlayer, new Insets(50,0,0,55));
//}
//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());
}

View File

@ -13,9 +13,9 @@
<image>
<Image url="@/gameFinishedImage.png" />
</image></ImageView>
<Label fx:id="nameWinner" alignment="CENTER_RIGHT" layoutX="453.0" layoutY="247.0" prefHeight="22.0" prefWidth="300.0" textAlignment="CENTER">
<Label fx:id="nameWinner" alignment="CENTER_RIGHT" layoutX="274.0" layoutY="236.0" prefHeight="51.0" prefWidth="488.0" textAlignment="CENTER" textFill="WHITE">
<font>
<Font name="Bell MT" size="40.0" />
<Font name="Verdana" size="40.0" />
</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="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,12 +7,17 @@ import java.util.ArrayList;
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.Player;
import latice.model.Position;
import latice.model.Rules;
import latice.model.Shape;
import latice.model.Tile;
import latice.model.console.Deck;
import latice.model.console.GameBoard;
import latice.model.console.Rack;
import latice.model.console.Score;
@ -202,26 +207,276 @@ 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());
}
/*@Test
void () {
@Test
void should_create_tile_image() {
//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(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)));
}
}