Merge branch 'Display_name_player_in_window' into 'master'
reorganisation of all packages | ADD Playgame, RectangleFX | See merge request odabasioglu1/latice!9master
commit
76a6581326
|
@ -6,14 +6,14 @@ import java.util.Scanner;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import latice.model.Color;
|
||||
import latice.model.Deck;
|
||||
import latice.model.GameBoard;
|
||||
import latice.model.Player;
|
||||
import latice.model.Rack;
|
||||
import latice.model.Rules;
|
||||
import latice.model.Score;
|
||||
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;
|
||||
|
||||
public class LaticeApplicationConsole {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package latice.application;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Parent;
|
||||
|
@ -37,15 +33,19 @@ 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.controller.MainScreenController;
|
||||
import latice.controller.PlayerNameInputController;
|
||||
import latice.model.Color;
|
||||
import latice.model.Deck;
|
||||
import latice.model.Rack;
|
||||
import latice.model.Player;
|
||||
import latice.model.Shape;
|
||||
import latice.model.Tile;
|
||||
import latice.model.console.Deck;
|
||||
import latice.model.console.Rack;
|
||||
import latice.model.console.Score;
|
||||
import latice.model.window.RectangleFX;
|
||||
|
||||
public class LaticeApplicationWindow extends Application {
|
||||
|
||||
|
@ -72,16 +72,22 @@ public class LaticeApplicationWindow extends Application {
|
|||
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
|
||||
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
|
||||
static StackPane rootLayout;
|
||||
private Label namePlayer1 = new Label("Anonym");
|
||||
private Label namePlayer2 = new Label("Anonym");
|
||||
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 root = new BorderPane();
|
||||
|
||||
//StackPane for background image + BorderPane root onto it
|
||||
StackPane stackPane = new StackPane();
|
||||
|
||||
static Stage primaryStageCopy;
|
||||
StackPane parentStackPane = new StackPane();
|
||||
Label moonErrorLabel = new Label();
|
||||
|
@ -102,7 +108,7 @@ public class LaticeApplicationWindow extends Application {
|
|||
Scene menu = new Scene(loader, 1280, 720);
|
||||
MainScreenController MSC = new MainScreenController();
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
//Title
|
||||
VBox topVbox = new VBox();
|
||||
Text title = new Text("Latice");
|
||||
|
@ -121,7 +127,7 @@ public class LaticeApplicationWindow extends Application {
|
|||
BackgroundSize.DEFAULT);
|
||||
stackPane.setBackground(new Background(myBG));
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
//Creating rectangle for tiles placement
|
||||
Rectangle[][] r = new Rectangle[9][9];
|
||||
int counterI = 0;
|
||||
|
@ -143,9 +149,32 @@ public class LaticeApplicationWindow extends Application {
|
|||
|
||||
root.setCenter(pane);
|
||||
System.out.println(r);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
//###################### Instantiating of players ######################///
|
||||
//create the list of all tiles
|
||||
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//setting decks for the 2 players
|
||||
Deck deck1 = new Deck(listOfTile);
|
||||
Deck deck2 = new Deck(listOfTile);
|
||||
|
||||
//setting player names
|
||||
//String name1 = PlayerNameInputController.getNomJoueur1().getText();
|
||||
//String name2 = PlayerNameInputController.getNomJoueur2().getText();
|
||||
|
||||
|
||||
|
||||
Player player1 = new Player(namePlayer1.getText(), new Score(), deck1, new Rack(deck1));
|
||||
Player player2 = new Player(namePlayer2.getText(), new Score(), deck2, new Rack(deck2));
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
//Rack
|
||||
|
@ -243,26 +272,13 @@ public class LaticeApplicationWindow extends Application {
|
|||
System.out.println((indexTileClicked));
|
||||
ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked()));
|
||||
|
||||
//Setting drag & drop on rectangles
|
||||
for(int i=0; i<NUMBER_OF_BOX_ON_ONE_LINE; i++) {
|
||||
for(int j=0; j<NUMBER_OF_BOX_ON_ONE_LINE; j++) {
|
||||
int a = i;
|
||||
int b = j;
|
||||
|
||||
r[a][b].setOnDragEntered(new EventHandler<DragEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
if (arg0.getDragboard().hasString()){
|
||||
Dragboard dragboard = arg0.getDragboard();
|
||||
|
||||
r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked())));
|
||||
}
|
||||
arg0.consume();
|
||||
}
|
||||
});
|
||||
|
||||
r[a][b].setOnDragExited(new EventHandler<DragEvent>() {
|
||||
//------------------------------------------------------------------------
|
||||
//###################### creating all rectangles and DragnDrop ######################//
|
||||
RectangleFX rectFX = new RectangleFX();
|
||||
rectFX.createRectangle(root, pane);
|
||||
rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount);
|
||||
rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount);
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
|
@ -316,19 +332,37 @@ public class LaticeApplicationWindow extends Application {
|
|||
});
|
||||
|
||||
|
||||
}
|
||||
Text name = new Text();
|
||||
name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20));
|
||||
name.setText(nameplayer.getName());
|
||||
|
||||
Text score = new Text();
|
||||
score.setText("Score : ");
|
||||
|
||||
Text nbrOfTiles = new Text();
|
||||
nbrOfTiles.setText("Tuiles restantes : ");
|
||||
|
||||
player.getChildren().addAll(name, score, nbrOfTiles);
|
||||
player.setSpacing(5);
|
||||
|
||||
players.getChildren().add(player);
|
||||
players.setMargin(player, new Insets(50,0,0,55));
|
||||
}
|
||||
|
||||
//rules / referee implementaion
|
||||
System.out.println("largeur : " + root.getMaxWidth());
|
||||
players.setSpacing(850);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
root.setLeft(namePlayer1);
|
||||
parentStackPane = MSC.getParentStackPane();
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
setPrimaryStage(primaryStage);
|
||||
setRootLayout(stackPane);
|
||||
stackPane.getChildren().add(root);
|
||||
stackPane.getChildren().addAll(players, root);
|
||||
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.setTitle("Latice");
|
||||
|
@ -391,30 +425,28 @@ public class LaticeApplicationWindow extends Application {
|
|||
LaticeApplicationWindow.indexTileClicked = indexTileClicked;
|
||||
}
|
||||
|
||||
//player names setters
|
||||
/*//player names setters
|
||||
public void setNamePlayer1(String namePlayer1) {
|
||||
this.namePlayer1.setText(namePlayer1);
|
||||
}
|
||||
|
||||
public void setNamePlayer2(String namePlayer2) {
|
||||
this.namePlayer2.setText(namePlayer2);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void playerNamesEntered() {
|
||||
System.out.println("entered playNamesEntered()" + namePlayer1.getText() + " VS " + namePlayer2.getText());
|
||||
HBox scoreHbox = new HBox();
|
||||
scoreHbox.getChildren().add(namePlayer1);
|
||||
scoreHbox.getChildren().add(namePlayer2);
|
||||
Text working = new Text("Working");
|
||||
root.setLeft(working);
|
||||
|
||||
MainScreenController MSC = new MainScreenController();
|
||||
MSC.setParentStackPane(parentStackPane);
|
||||
|
||||
primaryStageCopy.setTitle("working");
|
||||
}
|
||||
|
||||
public void displayMoonError() {
|
||||
public void transition(Label player1, Label player2) {
|
||||
|
||||
root.setLeft(player1);
|
||||
root.setRight(player2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package latice.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
|
@ -21,6 +22,13 @@ import javafx.stage.Modality;
|
|||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import latice.application.LaticeApplicationWindow;
|
||||
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;
|
||||
import latice.model.console.Score;
|
||||
|
||||
public class MainScreenController extends LaticeApplicationWindow{
|
||||
@FXML
|
||||
|
@ -36,6 +44,11 @@ public class MainScreenController extends LaticeApplicationWindow{
|
|||
public static Stage mainStage;
|
||||
private static StackPane parentStackPaneStock;
|
||||
|
||||
|
||||
|
||||
public Player player1;
|
||||
public Player player2;
|
||||
|
||||
// Event Listener on Rectangle[#playButton].onMouseClicked
|
||||
@FXML
|
||||
public void playButtonClicked(MouseEvent event) throws IOException {
|
||||
|
@ -141,4 +154,24 @@ public class MainScreenController extends LaticeApplicationWindow{
|
|||
this.parentStackPane = parentStackPane;
|
||||
}
|
||||
|
||||
public Player instanciatePlayer(String namePlayer) {
|
||||
//###################### Instantiating of players ######################///
|
||||
//create the list of all tiles
|
||||
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
//setting decks for the 2 players
|
||||
Deck deck = new Deck(listOfTile);
|
||||
Deck deck2 = new Deck(listOfTile);
|
||||
|
||||
Player player = new Player(namePlayer, new Score(), deck, new Rack(deck));
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package latice.controller;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import latice.application.LaticeApplicationWindow;
|
||||
|
||||
|
@ -28,12 +27,39 @@ public class PlayerNameInputController {
|
|||
//setting player names
|
||||
String name1 = nomJoueur1.getText();
|
||||
String name2 = nomJoueur2.getText();
|
||||
laticeApplicationWindow.setNamePlayer1(name1);
|
||||
laticeApplicationWindow.setNamePlayer2(name2);
|
||||
|
||||
|
||||
btnClicked = true;
|
||||
nameInputStage.close();
|
||||
laticeApplicationWindow.playerNamesEntered();
|
||||
playerNamesEntered();
|
||||
laticeApplicationWindow.player1 = mainScreenController.instanciatePlayer(name1);
|
||||
laticeApplicationWindow.player2 = mainScreenController.instanciatePlayer(name2);
|
||||
mainScreenController.startGameInstruction();
|
||||
}
|
||||
|
||||
public TextField getNomJoueur1() {
|
||||
return nomJoueur1;
|
||||
}
|
||||
|
||||
public void setNomJoueur1(TextField nomJoueur1) {
|
||||
this.nomJoueur1 = nomJoueur1;
|
||||
}
|
||||
|
||||
public TextField getNomJoueur2() {
|
||||
return nomJoueur2;
|
||||
}
|
||||
|
||||
public void setNomJoueur2(TextField nomJoueur2) {
|
||||
this.nomJoueur2 = nomJoueur2;
|
||||
}
|
||||
|
||||
public void playerNamesEntered() {
|
||||
System.out.println("entered playNamesEntered()" + nomJoueur1.getText() + " VS " + nomJoueur2.getText());
|
||||
|
||||
MainScreenController MSC = new MainScreenController();
|
||||
StackPane parentStackPane = MSC.getParentStackPane();
|
||||
MSC.setParentStackPane(parentStackPane);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,11 @@ package latice.model;
|
|||
|
||||
import java.util.Scanner;
|
||||
|
||||
import latice.model.console.Deck;
|
||||
import latice.model.console.GameBoard;
|
||||
import latice.model.console.Rack;
|
||||
import latice.model.console.Score;
|
||||
|
||||
public class Player {
|
||||
private final String name;
|
||||
private Score score;
|
||||
|
@ -9,17 +14,25 @@ public class Player {
|
|||
private Deck deck;
|
||||
|
||||
public Player(String name, Score score, Deck deck, Rack rack) {
|
||||
//Demande le nom du joueur
|
||||
Scanner enterPlayerName = new Scanner(System.in);
|
||||
System.out.println("Veuilez entrer votre nom " + name + " :");
|
||||
String namePlayer = enterPlayerName.next();
|
||||
|
||||
this.name = namePlayer;
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.deck = deck;
|
||||
this.rack = rack;
|
||||
}
|
||||
|
||||
/*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;
|
||||
}
|
||||
|
@ -32,6 +45,10 @@ public class Player {
|
|||
return this.score.getScore();
|
||||
}
|
||||
|
||||
public Integer getNumberOfTilesRemaining() {
|
||||
return this.deck.getListTile().size() + this.rack.getListRackTile().size();
|
||||
}
|
||||
|
||||
public Integer addScore(Integer value) {
|
||||
int newScore = this.score.getScore()+value;
|
||||
this.score.setScore(newScore);
|
||||
|
|
|
@ -3,6 +3,8 @@ package latice.model;
|
|||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import latice.model.console.GameBoard;
|
||||
|
||||
public class Rules {
|
||||
//private static boolean START = true;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package latice.model;
|
||||
package latice.model.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import latice.model.Tile;
|
||||
|
||||
public class Deck {
|
||||
private ArrayList<Tile> deckTile = new ArrayList<Tile>();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package latice.model;
|
||||
package latice.model.console;
|
||||
|
||||
public class GameBoard {
|
||||
private Integer DIMENSION = 9;
|
|
@ -1,4 +1,4 @@
|
|||
package latice.model;
|
||||
package latice.model.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -8,6 +8,7 @@ import javafx.scene.image.Image;
|
|||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Text;
|
||||
import latice.model.Tile;
|
||||
|
||||
public class Rack {
|
||||
private ArrayList<Tile> listRackTile = new ArrayList<Tile>();
|
|
@ -1,4 +1,4 @@
|
|||
package latice.model;
|
||||
package latice.model.console;
|
||||
|
||||
public class Score {
|
||||
private Integer score;
|
|
@ -0,0 +1,263 @@
|
|||
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 validateBtnClickedCount;
|
||||
|
||||
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, validateBtnClickedCount);
|
||||
rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
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) {
|
||||
|
||||
validateBtnClickedCount++;
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package latice.model.window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.input.DragEvent;
|
||||
import javafx.scene.input.Dragboard;
|
||||
import javafx.scene.input.TransferMode;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.ImagePattern;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import latice.model.Constant;
|
||||
import latice.model.Player;
|
||||
import latice.model.Tile;
|
||||
|
||||
public class RectangleFX {
|
||||
|
||||
javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0);
|
||||
Rectangle[][] rect = new Rectangle[9][9];
|
||||
ArrayList<Image> listTileImage;
|
||||
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
|
||||
|
||||
public void createRectangle(BorderPane board, Pane pane) {
|
||||
//Creating rectangle for tiles placement
|
||||
|
||||
int counterI = 0;
|
||||
int counterJ = 0;
|
||||
for (int i=1; i<= Constant.NUMBER_OF_BOX_ON_ONE_LINE ; i++) {
|
||||
for (int j=1; j <= Constant.NUMBER_OF_BOX_ON_ONE_LINE ; j++) {
|
||||
|
||||
rect[counterI][counterJ] = new Rectangle(i*Constant.BOX_WIDTH+Constant.X_CENTER,j*Constant.BOX_WIDTH+Constant.Y_CENTER,Constant.RECTANGLE_WIDTH,Constant.RECTANGLE_HEIGHT);
|
||||
rect[counterI][counterJ].setFill(realColor.TRANSPARENT);
|
||||
pane.getChildren().add(rect[counterI][counterJ]);
|
||||
System.out.println(rect[counterI][counterJ]);
|
||||
System.out.println(counterJ);
|
||||
counterJ++;
|
||||
}
|
||||
System.out.println(counterI);
|
||||
counterJ = 0;
|
||||
counterI++;
|
||||
}
|
||||
|
||||
board.setCenter(pane);
|
||||
System.out.println(rect);
|
||||
}
|
||||
|
||||
|
||||
public void dragnDropOnAllRectangles(Player player, Integer index, Integer validateBtnClicked) {
|
||||
|
||||
//Setting drag & drop on rectangles
|
||||
for(int i=0; i<Constant.NUMBER_OF_BOX_ON_ONE_LINE; i++) {
|
||||
for(int j=0; j<Constant.NUMBER_OF_BOX_ON_ONE_LINE; j++) {
|
||||
int a = i;
|
||||
int b = j;
|
||||
|
||||
rect[a][b].setOnDragEntered(new EventHandler<DragEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
if (arg0.getDragboard().hasString()){
|
||||
Dragboard dragboard = arg0.getDragboard();
|
||||
|
||||
rect[a][b].setFill(new ImagePattern(listTileImage.get(index)));
|
||||
}
|
||||
arg0.consume();
|
||||
}
|
||||
});
|
||||
|
||||
rect[a][b].setOnDragExited(new EventHandler<DragEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
if (arg0.isDropCompleted() == false) {
|
||||
rect[a][b].setFill(realColor.TRANSPARENT);
|
||||
}
|
||||
arg0.consume();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
rect[a][b].setOnDragOver(new EventHandler <DragEvent>() {
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
arg0.acceptTransferModes(TransferMode.ANY);
|
||||
arg0.consume();
|
||||
}
|
||||
});
|
||||
|
||||
rect[a][b].setOnDragDropped(new EventHandler<DragEvent>() {
|
||||
@Override
|
||||
public void handle(DragEvent arg0) {
|
||||
System.out.println("entered");
|
||||
Dragboard dragboard = arg0.getDragboard();
|
||||
|
||||
rect[a][b].setFill(new ImagePattern(listTileImage.get(index)));
|
||||
arg0.setDropCompleted(true);
|
||||
assocRectangleTile.put(rect[a][b], player.getRack().getListRackTile().get(index));
|
||||
System.out.println(assocRectangleTile.toString());
|
||||
if (validateBtnClicked == 0){
|
||||
if (rect[a][b] == rect[4][4]) {
|
||||
System.out.println("MOON valid placement");
|
||||
}else {
|
||||
System.out.println("Please place first Tile on MOON");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
arg0.consume();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue