UPDATE Player, LaticeApplicationWindow and LaticeApplicationConsole

master
Mathis 2022-06-06 15:09:01 +02:00
parent 83abebacdc
commit 5d3ff112eb
7 changed files with 89 additions and 106 deletions

View File

@ -106,8 +106,8 @@ public class LaticeApplicationConsole {
Score scorePlayer1 = new Score(); Score scorePlayer1 = new Score();
Score scorePlayer2 = new Score(); Score scorePlayer2 = new Score();
Player player1 = new Player("player1", scorePlayer1, deck1, rack1); Player player1 = new Player("player1", deck1);
Player player2 = new Player("player2", scorePlayer2, deck2, rack2); Player player2 = new Player("player2", deck2);
System.out.println("-----------------"); System.out.println("-----------------");
GameBoard board = new GameBoard(); GameBoard board = new GameBoard();

View File

@ -58,11 +58,10 @@ import latice.model.window.PlayerFX;
public class LaticeApplicationWindow extends Application { public class LaticeApplicationWindow extends Application {
Image image = new Image("backgroundLatice.png"); Image image = new Image("backgroundLatice.png");
ImageView imageView = new ImageView(image); ImageView imageView = new ImageView(image);
//lists for tiles
ArrayList<Tile> listRackTile; ArrayList<Tile> listRackTile;
ArrayList<Image> listRackImage; ArrayList<Image> listRackImage;
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
@ -70,10 +69,7 @@ public class LaticeApplicationWindow extends Application {
public static int indexTileClicked; public static int indexTileClicked;
//settings players //settings players
//public Player player1;
//public Player player2;
public Player player; public Player player;
// informations of the player // informations of the player
@ -84,23 +80,20 @@ public class LaticeApplicationWindow extends Application {
Button changeButton; Button changeButton;
Button buyActionButton; Button buyActionButton;
//setting the referee to check rules, the GameBoard where the tile are placed and the Rectangle to put the image tile in the plateau //setting the referee to check rules, the GameBoard where the tile are placed and the Rectangle to put the image tile in the game board
Rectangle[][] rect; Rectangle[][] rect;
GameBoard board; GameBoard board;
Rules referee; Rules referee;
//setting to know if the tile is well dropped with the check of rules or not //setting to know if the tile is well dropped with the check of rules or not
//To start, it's false //To start, it's false
Boolean tileDropped = false; Boolean tileDropped = false;
Paint tileOnRect; Paint tileOnRect;
//tile is free when it 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 freeOrPayableTile = true; Boolean freeOrPayableTile = true;
//borderPane layout
public static BorderPane borderPane = new BorderPane(); public static BorderPane borderPane = new BorderPane();
//StackPane for background image + BorderPane onto it //StackPane for background image + BorderPane onto it
@ -116,6 +109,8 @@ public class LaticeApplicationWindow extends Application {
int confirmBtnClickedCount; int confirmBtnClickedCount;
Parent loader;
static Scene menu;
public static void main(String[] args) { public static void main(String[] args) {
Application.launch(args); Application.launch(args);
@ -126,8 +121,9 @@ public class LaticeApplicationWindow extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception{
Parent loader = FXMLLoader.load(getClass().getResource("../view/MainScreen.fxml")); //setting main menu screen
Scene menu = new Scene(loader, 1280, 720); loader = FXMLLoader.load(getClass().getResource("../view/MainScreen.fxml"));
menu = new Scene(loader, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
MainScreenController MSC = new MainScreenController(); MainScreenController MSC = new MainScreenController();
@ -143,15 +139,25 @@ public class LaticeApplicationWindow extends Application {
} }
public void startGame(Stage stage, StackPane parentStackPaneStock, Player player1, Player player2, Object menuBorderPane) { public void startGame(Stage stage, StackPane parentStackPaneStock, Player player1, Player player2, Object menuBorderPane, Boolean isRestart) {
//changing layouts to start the game
parentStackPane = parentStackPaneStock; parentStackPane = parentStackPaneStock;
StackPane root = getRootLayout(); StackPane root = getRootLayout();
root.translateYProperty().set(stage.getHeight());
System.out.println(parentStackPane); System.out.println(parentStackPane);
System.out.println(parentStackPaneStock); System.out.println(parentStackPaneStock);
if (parentStackPane.getChildren().contains(root)) { if (isRestart) {
//if we're restarting the game then do some settings
System.out.println("Voici le menu : " + menu);
Constant.START = true;
stage.setScene(menu);
parentStackPane.getChildren().remove(root); parentStackPane.getChildren().remove(root);
} //parentStackPane.getChildren().add(root);
parentStackPane.getChildren().remove(menuBorderPane);
}else {
//else if it's the first time we're launching it
root.translateYProperty().set(stage.getHeight());
parentStackPane.getChildren().add(root); parentStackPane.getChildren().add(root);
@ -166,6 +172,7 @@ public class LaticeApplicationWindow extends Application {
parentStackPane.getChildren().remove(menuBorderPane); parentStackPane.getChildren().remove(menuBorderPane);
}); });
timeline.play(); timeline.play();
}
@ -177,12 +184,14 @@ public class LaticeApplicationWindow extends Application {
title.setFont(new Font(30)); title.setFont(new Font(30));
topVbox.getChildren().add(title); topVbox.getChildren().add(title);
topVbox.setAlignment(Pos.CENTER); topVbox.setAlignment(Pos.CENTER);
//error label for displaying errors
ErrorLabel.setFont(new Font(20)); ErrorLabel.setFont(new Font(20));
ErrorLabel.setTextFill(Constant.realColor.RED); ErrorLabel.setTextFill(Constant.realColor.RED);
topVbox.getChildren().add(ErrorLabel); topVbox.getChildren().add(ErrorLabel);
borderPane.setTop(topVbox); borderPane.setTop(topVbox);
//Image //background image
Pane pane = new Pane(); Pane pane = new Pane();
BackgroundImage myBG= new BackgroundImage(image, BackgroundImage myBG= new BackgroundImage(image,
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
@ -234,7 +243,9 @@ public class LaticeApplicationWindow extends Application {
//----------- group all players in a HBox to display -----------// //----------- group all players in a HBox to display -----------//
HBox infoPlayers = new HBox(); HBox infoPlayers = new HBox();
infoPlayers.getChildren().addAll(infoPlayer1, infoPlayer2); infoPlayers.getChildren().addAll(infoPlayer1, infoPlayer2);
HBox.setMargin(infoPlayer1, new Insets(50,0,0,55)); HBox.setMargin(infoPlayer1, new Insets(50,0,0,55));
HBox.setMargin(infoPlayer2, new Insets(50,0,0,55)); HBox.setMargin(infoPlayer2, new Insets(50,0,0,55));
infoPlayers.setSpacing(850); infoPlayers.setSpacing(850);
@ -264,7 +275,6 @@ public class LaticeApplicationWindow extends Application {
System.out.println("-----------------"); System.out.println("-----------------");
Rack rack = new Rack(deck); Rack rack = new Rack(deck);
System.out.println("-----------------"); System.out.println("-----------------");
//deck.displayListTile();
//Player //Player
@ -296,6 +306,7 @@ public class LaticeApplicationWindow extends Application {
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
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
@ -306,7 +317,6 @@ public class LaticeApplicationWindow extends Application {
try { try {
switchToGameFinishedScreen(); switchToGameFinishedScreen();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -314,22 +324,9 @@ public class LaticeApplicationWindow extends Application {
player.getRack().displayRack(); player.getRack().displayRack();
player.getRack().updateRack(); player.getRack().updateRack();
//HBox newRackImage = rack2.createTileImage();
//rackImage.getChildren().clear();
//listRackTile = rack2.getListRackTile();
//System.out.println(listRackTile);
player.getRack().displayRack(); player.getRack().displayRack();
//making names colored in red to make the players know which player's round is
//Setting drag n drop on tiles
//setDragnDropOnRectangles(rect, board, referee, player);
if (confirmBtnClickedCount%2 == 0) { if (confirmBtnClickedCount%2 == 0) {
playerFX.setFillName(Constant.realColor.BLACK); playerFX.setFillName(Constant.realColor.BLACK);
player = player1; player = player1;
@ -354,16 +351,20 @@ public class LaticeApplicationWindow extends Application {
} }
private void switchToGameFinishedScreen() throws IOException { private void switchToGameFinishedScreen() throws IOException {
//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, 1280, 720); Scene gameFinishedScreenScene = new Scene(loader, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
if (player1.getNumberOfTilesRemaining() < player2.getNumberOfTilesRemaining()) { if (player1.getNumberOfTilesRemaining() < player2.getNumberOfTilesRemaining()) {
// if player 1 has less tiles then he wins // if player 1 has less tiles then he wins
GameFinishedScreenController.staticNameWinner.setText(player1.getName()); GameFinishedScreenController.staticNameWinner.setText(player1.getName());
GameFinishedScreenController.staticNameLooser.setText(player2.getName());
}else { }else {
//if player 2 has less tiles then he wins //if player 2 has less tiles then he wins
GameFinishedScreenController.staticNameWinner.setText(player2.getName()); GameFinishedScreenController.staticNameWinner.setText(player2.getName());
GameFinishedScreenController.staticNameLooser.setText(player1.getName());
} }
stage.setScene(gameFinishedScreenScene); stage.setScene(gameFinishedScreenScene);
@ -377,9 +378,7 @@ public class LaticeApplicationWindow extends Application {
}); });
//With Image //With Image
//Rack player.getRack() = new Rack(deck);
rackImage = player.getRack().createTileImage(); rackImage = player.getRack().createTileImage();
//Adding lists to Arraylists //Adding lists to Arraylists
@ -387,25 +386,12 @@ public class LaticeApplicationWindow extends Application {
System.out.println(listRackTile); System.out.println(listRackTile);
listRackImage = player.getRack().getRackTileImage(); listRackImage = player.getRack().getRackTileImage();
System.out.println("listTileImge : " + listRackImage); System.out.println("listTileImge : " + listRackImage);
//HBox rackTile = rack2.createTileImage();
changeButton.setOnMouseClicked(new EventHandler<MouseEvent>() { changeButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
//player.getRack().changeRack();
//HBox newRackImage = rack2.createTileImage();
//rackImage.getChildren().clear();
//listRackTile = rack2.getListRackTile();
//System.out.println(listRackTile);
////// for the actual player ////// ////// for the actual player //////
if (player.getScore() > 1) { if (player.getScore() > 1) {
System.out.println("Changing Rack"); System.out.println("Changing Rack");
@ -463,18 +449,11 @@ public class LaticeApplicationWindow extends Application {
}); });
//HBox rackTile = rack2.createTileImage();
rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); rackImage.getChildren().addAll(confirmButton, changeButton, buyActionButton);
setDragnDropOnRack(rackImage, player); setDragnDropOnRack(rackImage, player);
System.out.println(); System.out.println();
borderPane.setBottom(rackImage); borderPane.setBottom(rackImage);
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//Setting drag n drop on tiles //Setting drag n drop on tiles
@ -484,12 +463,7 @@ public class LaticeApplicationWindow extends Application {
ImagePattern imagePattern = new ImagePattern(listRackImage.get(getIndexTileClicked())); ImagePattern imagePattern = new ImagePattern(listRackImage.get(getIndexTileClicked()));
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//###################### creating all rectangles and DragnDrop ######################//
//RectangleFX rectFX = new RectangleFX();
//rectFX.createRectangle(root, pane);
//rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount);
//rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount);
//------------------------------------------------------------------------
//Setting drag & drop on rectangles //Setting drag & drop on rectangles
setDragnDropOnRectangles(rect, board, referee, player); setDragnDropOnRectangles(rect, board, referee, player);
@ -497,8 +471,9 @@ public class LaticeApplicationWindow extends Application {
//-------------------------------------------------------------------------------------- //------if there is already childrens, remove them all to start or restart game------------------------------------------------------------
root.getChildren().clear();
//adding new childrens
root.getChildren().addAll(infoPlayers, borderPane); root.getChildren().addAll(infoPlayers, borderPane);
@ -524,7 +499,7 @@ public class LaticeApplicationWindow extends Application {
if (arg0.getDragboard().hasString()){ if (arg0.getDragboard().hasString()){
Dragboard dragboard = arg0.getDragboard(); Dragboard dragboard = arg0.getDragboard();
//not put 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)));
@ -578,7 +553,8 @@ public class LaticeApplicationWindow extends Application {
}else { }else {
if (Constant.START) { if (Constant.START) {
if (rect[a][b] == rect[4][4]) { if (rect[a][b] == rect[Constant.MOON_BOX_X][Constant.MOON_BOX_Y]) {
//if its's the center box (moon box)
System.out.println("MOON valid placement"); System.out.println("MOON valid placement");
board.setGridBoardTile(player.getRack().getListRackTile().get(indexTileClicked), a, b); board.setGridBoardTile(player.getRack().getListRackTile().get(indexTileClicked), a, b);
@ -596,18 +572,18 @@ public class LaticeApplicationWindow extends Application {
} }
}else { }else {
//if it's not the first round of the game
System.out.println("OK3"); System.out.println("OK3");
System.out.println("Règle effectué"); 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
if ( referee.checkPositionRule(board, player.getRack().getListRackTile().get(indexTileClicked)) == false ) { 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"); 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 {
//if there is not already a tile
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) {
@ -638,7 +614,7 @@ public class LaticeApplicationWindow extends Application {
freeOrPayableTile = false; freeOrPayableTile = false;
System.out.println("tuile posé!"); System.out.println("tuile posé!");
//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");
playerFX.setAddScore(player, 2); playerFX.setAddScore(player, 2);
@ -650,13 +626,6 @@ public class LaticeApplicationWindow extends Application {
} }
arg0.consume(); arg0.consume();
} }

View File

@ -23,12 +23,15 @@ public class GameFinishedScreenController implements Initializable{
private Label nameWinner; private Label nameWinner;
public static Label staticNameWinner; public static Label staticNameWinner;
public static Label staticNameLooser = new Label();
// Event Listener on Button[#replayBtn].onMouseClicked // Event Listener on Button[#replayBtn].onMouseClicked
@FXML @FXML
public void replayBtnClicked(MouseEvent event) { public void replayBtnClicked(MouseEvent event) {
MainScreenController MSC = new MainScreenController(); MainScreenController MSC = new MainScreenController();
MSC.startGameInstruction(); MSC.player1 = MSC.instanciatePlayer(staticNameWinner.getText());
MSC.player2 = MSC.instanciatePlayer(staticNameLooser.getText());
MSC.startGameInstruction(true);
System.out.println("replayBtnClicked"); System.out.println("replayBtnClicked");
} }
// Event Listener on Button[#quitBtn].onMouseClicked // Event Listener on Button[#quitBtn].onMouseClicked

View File

@ -124,9 +124,10 @@ public class MainScreenController extends LaticeApplicationWindow{
nameInputStage.show(); nameInputStage.show();
} }
public void startGameInstruction() { public void startGameInstruction(Boolean isRestart) {
startGame(mainStage, parentStackPaneStock, player1, player2, menuBorderPane, isRestart);
startGame(mainStage, parentStackPaneStock, player1, player2, menuBorderPane);
} }
/*public void startGame(Stage stage) { /*public void startGame(Stage stage) {
@ -184,7 +185,7 @@ public class MainScreenController extends LaticeApplicationWindow{
Deck deck = new Deck(listOfTile); Deck deck = new Deck(listOfTile);
Deck deck2 = new Deck(listOfTile); Deck deck2 = new Deck(listOfTile);
Player player = new Player(namePlayer, new Score(), deck, new Rack(deck)); Player player = new Player(namePlayer, deck);
return player; return player;
} }

View File

@ -53,7 +53,7 @@ public class PlayerNameInputController {
if(nomJoueur2.getText().length() < 3 || nomJoueur2.getText().length() > 16) { if(nomJoueur2.getText().length() < 3 || nomJoueur2.getText().length() > 16) {
label2.setVisible(true); label2.setVisible(true);
} }
else { if ((nomJoueur1.getText().length() >= 3 && nomJoueur1.getText().length() <= 16 ) && (nomJoueur2.getText().length() >= 3 && nomJoueur2.getText().length() <= 16)) {
Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
//setting player names //setting player names
@ -72,7 +72,7 @@ public class PlayerNameInputController {
mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); mainScreenController.player2 = mainScreenController.instanciatePlayer(name2);
//PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2);
mainScreenController.startGameInstruction(); mainScreenController.startGameInstruction(false);
} }
} }

View File

@ -4,6 +4,12 @@ public class Constant {
//for the start of the game //for the start of the game
public static Boolean START = true; public static Boolean START = true;
public static final int SCREEN_HEIGHT = 720;
public static final int SCREEN_WIDTH = 1280;
public static final int MOON_BOX_Y = 4;
public static final int MOON_BOX_X = 4;
//for creating rectangles //for creating rectangles
public static final int NUMBER_OF_BOX_ON_ONE_LINE = 9; public static final int NUMBER_OF_BOX_ON_ONE_LINE = 9;

View File

@ -20,6 +20,10 @@ public class Player {
this.rack = rack; this.rack = rack;
} }
public Player(String name, Deck deck) {
this(name, new Score(), deck, new Rack(deck));
}
/*public Player(Score score, Deck deck, Rack rack) { /*public Player(Score score, Deck deck, Rack rack) {
this(namePlayer,score,deck,rack); this(namePlayer,score,deck,rack);
//Demande le nom du joueur //Demande le nom du joueur