Merge branch 'Latice_Console_2.0' into 'master'
merging latice console and master See merge request odabasioglu1/latice!6master
commit
73366ec789
|
@ -1,13 +1,16 @@
|
||||||
package latice.application;
|
package latice.application;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import latice.model.Color;
|
import latice.model.Color;
|
||||||
import latice.model.Deck;
|
import latice.model.Deck;
|
||||||
import latice.model.GameBoard;
|
import latice.model.GameBoard;
|
||||||
import latice.model.Player;
|
import latice.model.Player;
|
||||||
import latice.model.Rack;
|
import latice.model.Rack;
|
||||||
|
import latice.model.Rules;
|
||||||
import latice.model.Score;
|
import latice.model.Score;
|
||||||
import latice.model.Shape;
|
import latice.model.Shape;
|
||||||
import latice.model.Tile;
|
import latice.model.Tile;
|
||||||
|
@ -110,14 +113,109 @@ public class LaticeApplicationConsole {
|
||||||
GameBoard board = new GameBoard();
|
GameBoard board = new GameBoard();
|
||||||
board.displayGameBoard();
|
board.displayGameBoard();
|
||||||
|
|
||||||
|
System.out.println(Objects.equals(board.getGridBoard()[1][0], Tile.class));
|
||||||
Scanner play = new Scanner(System.in);
|
Scanner play = new Scanner(System.in);
|
||||||
|
Player player;
|
||||||
|
Boolean round;
|
||||||
|
Tile tile = null;
|
||||||
|
Boolean start = true;
|
||||||
|
Boolean freeTile;
|
||||||
|
Rules arbitre = new Rules();
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < 20; i++) {
|
||||||
|
round = true;
|
||||||
|
freeTile = true;
|
||||||
|
|
||||||
player1.Play(play,board);
|
if (i%2 == 0) {
|
||||||
player2.Play(play,board);
|
player = player1;
|
||||||
|
}else {
|
||||||
|
player = player2;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (round) {
|
||||||
|
System.out.println("c'est à votre tour de jouer " + player.getName() +"!");
|
||||||
|
System.out.println("Vous avez " + player.getScore() +", donc 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"
|
||||||
|
+ " 3. Changer le Rack et passer(coûte 3 points)\n"
|
||||||
|
+ " 4. Passer\n");
|
||||||
|
|
||||||
|
int choiceMenu = Integer.parseInt(play.next());
|
||||||
|
switch(choiceMenu) {
|
||||||
|
case 1: //if (arbitre.checkScore(freeTile)){
|
||||||
|
//System.out.println("Vous n'avez pas assez de points pour jouer un nouvelle tuile");
|
||||||
|
//}else {
|
||||||
|
Boolean rulesCheck = false;
|
||||||
|
|
||||||
|
while (rulesCheck == false) {
|
||||||
|
|
||||||
|
tile = player.Play(play,board,i);
|
||||||
|
rulesCheck = arbitre.arbitration(player, board, tile, start);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
start = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
board.setGridBoard(" "+tile.getShapeConsole()+tile.getColorConsole()+" ", tile.getPositionRow(), tile.getPositionColumn());
|
||||||
|
|
||||||
|
player.getRack().removeTile(tile);
|
||||||
|
board.displayGameBoard();
|
||||||
|
//}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
|
||||||
|
case 3: player.getRack().changeRack();
|
||||||
|
System.out.println("Votre rack à été changé avec succès !");
|
||||||
|
|
||||||
|
case 4: System.out.println("Votre tour est terminé " + player.getName() + " !");
|
||||||
|
round = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: throw new IllegalArgumentException("Veuillez choisir un nombre entre 1 et 4!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (PlayOrPass == 2) {
|
||||||
|
round = false;
|
||||||
|
System.out.println("Votre tour est terminé " + player.getName() + " !");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (round) {
|
||||||
|
Boolean rulesCheck = false;
|
||||||
|
|
||||||
|
System.out.println("c'est à votre tour de jouer " + player.getName() +"!");
|
||||||
|
|
||||||
|
while (rulesCheck == false) {
|
||||||
|
tile = player.Play(play,board,i);
|
||||||
|
rulesCheck = arbitre.arbitration(player, board, tile, START);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
START = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
board.setGridBoard(" "+tile.getShapeConsole()+tile.getColorConsole()+" ", tile.getPositionRow(), tile.getPositionColumn());
|
||||||
|
|
||||||
|
player.getRack().removeTile(tile);
|
||||||
|
board.displayGameBoard();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(player.getName() + " ! Voulez-vous passer votre tour ou continuer à jouer ? 1.continuer ou 2.passer");
|
||||||
|
int ContinueOrPass = Integer.parseInt(play.next());
|
||||||
|
if (ContinueOrPass == 2) {
|
||||||
|
round = false;
|
||||||
|
System.out.println("Votre tour est terminé " + player.getName() + " !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.getRack().updateRack();*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import javafx.geometry.Pos;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.ClipboardContent;
|
import javafx.scene.input.ClipboardContent;
|
||||||
|
@ -38,6 +39,7 @@ import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import latice.controller.MainScreenController;
|
import latice.controller.MainScreenController;
|
||||||
|
import latice.controller.PlayerNameInputController;
|
||||||
import latice.model.Color;
|
import latice.model.Color;
|
||||||
import latice.model.Deck;
|
import latice.model.Deck;
|
||||||
import latice.model.Rack;
|
import latice.model.Rack;
|
||||||
|
@ -72,10 +74,18 @@ public class LaticeApplicationWindow extends Application {
|
||||||
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
|
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
|
||||||
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
|
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
|
||||||
static StackPane rootLayout;
|
static StackPane rootLayout;
|
||||||
|
private Label namePlayer1 = new Label();
|
||||||
|
private Label namePlayer2 = new Label();
|
||||||
|
|
||||||
public static int indexTileClicked;
|
public static int indexTileClicked;
|
||||||
|
|
||||||
|
//root layout
|
||||||
|
BorderPane root = new BorderPane();
|
||||||
|
|
||||||
|
//StackPane for background image + BorderPane root onto it
|
||||||
|
StackPane stackPane = new StackPane();
|
||||||
|
static Stage primaryStageCopy;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,10 +103,7 @@ public class LaticeApplicationWindow extends Application {
|
||||||
Scene menu = new Scene(loader, 1280, 720);
|
Scene menu = new Scene(loader, 1280, 720);
|
||||||
MainScreenController MSC = new MainScreenController();
|
MainScreenController MSC = new MainScreenController();
|
||||||
|
|
||||||
//StackPane for background image + BorderPane root onto it
|
|
||||||
StackPane stackPane = new StackPane();
|
|
||||||
//root layout
|
|
||||||
BorderPane root = new BorderPane();
|
|
||||||
|
|
||||||
//Title
|
//Title
|
||||||
Text title = new Text("Latice");
|
Text title = new Text("Latice");
|
||||||
|
@ -276,10 +283,10 @@ public class LaticeApplicationWindow extends Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root.setLeft(namePlayer1);
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
setPrimaryStage(primaryStage);
|
||||||
setRootLayout(stackPane);
|
setRootLayout(stackPane);
|
||||||
stackPane.getChildren().add(root);
|
stackPane.getChildren().add(root);
|
||||||
|
|
||||||
|
@ -302,9 +309,9 @@ public class LaticeApplicationWindow extends Application {
|
||||||
public static int getIndexTileClicked() {
|
public static int getIndexTileClicked() {
|
||||||
return indexTileClicked;
|
return indexTileClicked;
|
||||||
}
|
}
|
||||||
|
public void setPrimaryStage(Stage primaryStage) {
|
||||||
|
this.primaryStageCopy = primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Setter to set the mouse clicked tile
|
//Setter to set the mouse clicked tile
|
||||||
|
@ -312,6 +319,23 @@ public class LaticeApplicationWindow extends Application {
|
||||||
LaticeApplicationWindow.indexTileClicked = indexTileClicked;
|
LaticeApplicationWindow.indexTileClicked = indexTileClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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 + " VS " + namePlayer2);
|
||||||
|
HBox scoreHbox = new HBox();
|
||||||
|
scoreHbox.getChildren().add(namePlayer1);
|
||||||
|
scoreHbox.getChildren().add(namePlayer2);
|
||||||
|
Text working = new Text("Working");
|
||||||
|
root.setLeft(working);
|
||||||
|
primaryStageCopy.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package latice.controller;
|
package latice.controller;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import javafx.animation.Interpolator;
|
import javafx.animation.Interpolator;
|
||||||
import javafx.animation.KeyFrame;
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.KeyValue;
|
import javafx.animation.KeyValue;
|
||||||
import javafx.animation.Timeline;
|
import javafx.animation.Timeline;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
|
@ -29,28 +33,22 @@ public class MainScreenController extends LaticeApplicationWindow{
|
||||||
private StackPane parentStackPane;
|
private StackPane parentStackPane;
|
||||||
@FXML
|
@FXML
|
||||||
private BorderPane menuBorderPane;
|
private BorderPane menuBorderPane;
|
||||||
|
public static Stage mainStage;
|
||||||
|
private static StackPane parentStackPaneStock;
|
||||||
|
|
||||||
// Event Listener on Rectangle[#playButton].onMouseClicked
|
// Event Listener on Rectangle[#playButton].onMouseClicked
|
||||||
@FXML
|
@FXML
|
||||||
public void playButtonClicked(MouseEvent event) {
|
public void playButtonClicked(MouseEvent event) throws IOException {
|
||||||
|
System.out.println(parentStackPane);
|
||||||
|
parentStackPaneStock = parentStackPane;
|
||||||
System.out.println("playButtonClicked");
|
System.out.println("playButtonClicked");
|
||||||
Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
|
mainStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
|
||||||
StackPane root = getRootLayout();
|
System.out.println(mainStage);
|
||||||
root.translateYProperty().set(primaryStage.getHeight());
|
if (!PlayerNameInputController.btnClicked) {
|
||||||
parentStackPane.getChildren().add(root);
|
playerNamesInput(event);
|
||||||
|
|
||||||
//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();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Event Listener on Rectangle[#rulesButton].onMouseClicked
|
// Event Listener on Rectangle[#rulesButton].onMouseClicked
|
||||||
@FXML
|
@FXML
|
||||||
public void rulesButtonClicked(MouseEvent event) {
|
public void rulesButtonClicked(MouseEvent event) {
|
||||||
|
@ -86,4 +84,52 @@ public class MainScreenController extends LaticeApplicationWindow{
|
||||||
System.out.println("exitButtonClicked");
|
System.out.println("exitButtonClicked");
|
||||||
Platform.exit();
|
Platform.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playerNamesInput(MouseEvent event) throws IOException {
|
||||||
|
Parent loader = FXMLLoader.load(getClass().getResource("../view/PlayerNameInput.fxml"));
|
||||||
|
Scene nameInputScene = new Scene(loader, 600, 300);
|
||||||
|
Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
|
||||||
|
|
||||||
|
// New window (Stage)
|
||||||
|
Stage nameInputStage = new Stage();
|
||||||
|
nameInputStage.setTitle("Names");
|
||||||
|
nameInputStage.setScene(nameInputScene);
|
||||||
|
|
||||||
|
// Specifies the modality for new window
|
||||||
|
nameInputStage.initModality(Modality.WINDOW_MODAL);
|
||||||
|
|
||||||
|
// Specifies the owner window
|
||||||
|
nameInputStage.initOwner(primaryStage);
|
||||||
|
|
||||||
|
// Set position of window
|
||||||
|
nameInputStage.setX(primaryStage.getX() + 300);
|
||||||
|
nameInputStage.setY(primaryStage.getY() + 175);
|
||||||
|
|
||||||
|
nameInputStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startGameInstruction() {
|
||||||
|
startGame(mainStage);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
//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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
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.stage.Stage;
|
||||||
|
import latice.application.LaticeApplicationWindow;
|
||||||
|
|
||||||
|
public class PlayerNameInputController {
|
||||||
|
@FXML
|
||||||
|
private TextField nomJoueur1;
|
||||||
|
@FXML
|
||||||
|
private TextField nomJoueur2;
|
||||||
|
@FXML
|
||||||
|
public Button btnValid;
|
||||||
|
public static boolean btnClicked = false;
|
||||||
|
MainScreenController mainScreenController = new MainScreenController();
|
||||||
|
LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void validBtnClicked(MouseEvent event) {
|
||||||
|
System.out.println("valid Button Clicked");
|
||||||
|
Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
|
||||||
|
//setting player names
|
||||||
|
String name1 = nomJoueur1.getText();
|
||||||
|
String name2 = nomJoueur2.getText();
|
||||||
|
laticeApplicationWindow.setNamePlayer1(name1);
|
||||||
|
laticeApplicationWindow.setNamePlayer2(name2);
|
||||||
|
btnClicked = true;
|
||||||
|
nameInputStage.close();
|
||||||
|
laticeApplicationWindow.playerNamesEntered();
|
||||||
|
mainScreenController.startGameInstruction();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ public class GameBoard {
|
||||||
private Integer DIMENSION = 9;
|
private Integer DIMENSION = 9;
|
||||||
public static final String SUN = " SU ";
|
public static final String SUN = " SU ";
|
||||||
public static final String MOON = " MO ";
|
public static final String MOON = " MO ";
|
||||||
|
public static final String BLUE = " ";
|
||||||
|
|
||||||
private String[][] gridBoard;
|
private String[][] gridBoard;
|
||||||
|
|
||||||
public GameBoard() {
|
public GameBoard() {
|
||||||
|
@ -30,7 +32,7 @@ public class GameBoard {
|
||||||
this.gridBoard[i][j] = SUN;
|
this.gridBoard[i][j] = SUN;
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
this.gridBoard[i][j] = " ";
|
this.gridBoard[i][j] = BLUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j == 8) {
|
if (j == 8) {
|
||||||
|
@ -67,6 +69,7 @@ public class GameBoard {
|
||||||
|
|
||||||
if (j == 8) {
|
if (j == 8) {
|
||||||
System.out.println("|");
|
System.out.println("|");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,28 @@ public class Player {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rack getRack() {
|
||||||
|
return this.rack;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getScore() {
|
public Integer getScore() {
|
||||||
return this.score.getScore();
|
return this.score.getScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play(Scanner play, GameBoard board) {
|
public Integer addScore(Integer value) {
|
||||||
System.out.println("c'est à votre tour de jouer " + this.name +"!");
|
int newScore = this.score.getScore()+value;
|
||||||
|
this.score.setScore(newScore);
|
||||||
|
return this.score.getScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer diffScore(Integer value) {
|
||||||
|
int newScore = this.score.getScore()-value;
|
||||||
|
this.score.setScore(newScore);
|
||||||
|
return this.score.getScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile Play(Scanner play, GameBoard board, Integer start) {
|
||||||
|
|
||||||
if (this.getScore() == 0) {
|
if (this.getScore() == 0) {
|
||||||
|
|
||||||
System.out.println("Vous avez " + this.getScore() + " point");
|
System.out.println("Vous avez " + this.getScore() + " point");
|
||||||
|
@ -41,17 +57,23 @@ public class Player {
|
||||||
|
|
||||||
System.out.print("Quel tuile voulez-vous jouez ? ");
|
System.out.print("Quel tuile voulez-vous jouez ? ");
|
||||||
this.rack.displayRack();
|
this.rack.displayRack();
|
||||||
String tileToPlay = play.next();
|
System.out.println(1);
|
||||||
|
Integer idTileToPlay = Integer.parseInt(play.next())-1;
|
||||||
|
Tile tileToPlay = this.rack.getListRackTile().get(idTileToPlay);
|
||||||
System.out.print("Sur quelle ligne, voulez-vous placer la tuile ?");
|
System.out.print("Sur quelle ligne, voulez-vous placer la tuile ?");
|
||||||
int row = Integer.parseInt(play.next());
|
int row = Integer.parseInt(play.next());
|
||||||
System.out.print("Sur quelle colonne, voulez-vous placer la tuile ?");
|
System.out.print("Sur quelle colonne, voulez-vous placer la tuile ?");
|
||||||
int column = Integer.parseInt(play.next());
|
int column = Integer.parseInt(play.next());
|
||||||
board.setGridBoard(" "+tileToPlay+" ", row, column);
|
|
||||||
this.rack.removeTile(tileToPlay);
|
|
||||||
|
|
||||||
board.displayGameBoard();
|
tileToPlay.setPosition(new Position(row, column));
|
||||||
|
return tileToPlay;
|
||||||
|
|
||||||
this.rack.updateRack();
|
//.setGridBoard(" "+tileToPlay.getShapeConsole()+tileToPlay.getColorConsole()+" ", row, column);
|
||||||
|
//this.rack.removeTile(tileToPlay);
|
||||||
|
|
||||||
|
//board.displayGameBoard();
|
||||||
|
|
||||||
|
//this.rack.updateRack();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ public class Rack {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Tile> getListRackTile() {
|
public ArrayList<Tile> getListRackTile() {
|
||||||
System.out.println(this.listRackTile);
|
|
||||||
return this.listRackTile;
|
return this.listRackTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,13 +63,14 @@ public class Rack {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTile(String stringTile) {
|
public void removeTile(Tile tileToDelete) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
System.out.println("taille : " + this.listRackTile.size());
|
System.out.println("taille : " + this.listRackTile.size());
|
||||||
|
String strTileToDelete = tileToDelete.getShapeConsole()+tileToDelete.getColorConsole();
|
||||||
for (Tile tile : this.listRackTile) {
|
for (Tile tile : this.listRackTile) {
|
||||||
System.out.println(count++);
|
System.out.println(count++);
|
||||||
if (stringTile.equals(tile.getShapeConsole() + tile.getColorConsole())) {
|
if (strTileToDelete.equals(tile.getShapeConsole()+tile.getColorConsole())) {
|
||||||
index = this.listRackTile.indexOf(tile);
|
index = this.listRackTile.indexOf(tile);
|
||||||
System.out.println(index);
|
System.out.println(index);
|
||||||
System.out.println("tuile supprimé avec succès");
|
System.out.println("tuile supprimé avec succès");
|
||||||
|
@ -85,16 +85,41 @@ public class Rack {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeRack() {
|
||||||
|
|
||||||
|
Tile tile;
|
||||||
|
int listRackTileSize = this.listRackTile.size();
|
||||||
|
|
||||||
|
for (int i = 0; i < listRackTileSize ; i++) {
|
||||||
|
|
||||||
|
tile = this.listRackTile.get(0);
|
||||||
|
this.deck.getListTile().add(tile);
|
||||||
|
this.listRackTile.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < listRackTileSize ; i++) {
|
||||||
|
int index = (int)(Math.random()*( ((this.deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min);
|
||||||
|
|
||||||
|
tile = (this.deck.getListTile()).get(index);
|
||||||
|
this.listRackTile.add(tile);
|
||||||
|
this.deck.getListTile().remove(index);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void displayRack() {
|
public void displayRack() {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
Integer tile_id = 1;
|
||||||
System.out.print("rack : ");
|
System.out.print("rack : ");
|
||||||
for (Tile tile : this.listRackTile) {
|
for (Tile tile : this.listRackTile) {
|
||||||
if (success) {
|
if (success) {
|
||||||
System.out.print(", " + tile.getShapeConsole() + tile.getColorConsole());
|
System.out.print(", " + tile_id + "." + tile.getShapeConsole() + tile.getColorConsole());
|
||||||
}else {
|
}else {
|
||||||
System.out.print(tile.getShapeConsole() + tile.getColorConsole());
|
System.out.print(tile_id + "." + tile.getShapeConsole() + tile.getColorConsole());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
tile_id = tile_id + 1;
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,111 @@
|
||||||
package latice.model;
|
package latice.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Rules {
|
public class Rules {
|
||||||
private static boolean START = true;
|
//private static boolean START = true;
|
||||||
|
|
||||||
public Rules() {
|
public Rules() {
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean moonRule(GameBoard board, Tile tile) {
|
||||||
|
if (GameBoard.MOON.equals(board.getGridBoard()[tile.getPositionRow()][tile.getPositionColumn()])) {
|
||||||
|
System.out.println("La première tuile se trouve bien sur la lune !");
|
||||||
|
return true;
|
||||||
|
}else {
|
||||||
|
System.out.println("La première tuile doit être placé sur la lune, recommencez !");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer neighborRule(GameBoard board, Tile tile) {
|
||||||
|
|
||||||
|
Integer nbrNeighbor = 0;
|
||||||
|
String checkNeighbor = null;
|
||||||
|
Boolean checkCase = false;
|
||||||
|
|
||||||
|
for(int i = 0; i < 2 ; i++) {
|
||||||
|
for(int j = -1; j < 2 ; j=j+2) {
|
||||||
|
if (i == 0) {
|
||||||
|
if (tile.getPositionColumn()+j >= 0 && tile.getPositionColumn()+j <= 9) {
|
||||||
|
checkNeighbor = board.getGridBoard()[tile.getPositionRow()][tile.getPositionColumn()+j];
|
||||||
|
checkCase = true;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (tile.getPositionRow()+j >= 0 && tile.getPositionRow()+j <= 9) {
|
||||||
|
checkNeighbor = board.getGridBoard()[tile.getPositionRow()+j][tile.getPositionColumn()];
|
||||||
|
checkCase = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkCase) {
|
||||||
|
if (!(GameBoard.SUN.equals(checkNeighbor)) || !(GameBoard.BLUE.equals(checkNeighbor))) {
|
||||||
|
|
||||||
|
System.out.println("Il y a une tuile");
|
||||||
|
|
||||||
|
if ( tile.getShapeConsole().equals(checkNeighbor.substring(1, 2)) || tile.getColorConsole().equals(checkNeighbor.substring(2, 3)) ) {
|
||||||
|
System.out.println("Il y a correspondance avec la tuile !");
|
||||||
|
nbrNeighbor = nbrNeighbor + 1;
|
||||||
|
}else {
|
||||||
|
System.out.println("Il n'y a pas correspondance avec la tuile !");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nbrNeighbor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean sunRule(GameBoard board, Tile tile) {
|
||||||
|
|
||||||
|
Boolean sun;
|
||||||
|
|
||||||
|
if (GameBoard.SUN.equals(board.getGridBoard()[tile.getPositionRow()][tile.getPositionColumn()])) {
|
||||||
|
sun = true;
|
||||||
|
}else {
|
||||||
|
sun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sun;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean arbitration(Player player, GameBoard board, Tile tile, Boolean start) {
|
||||||
|
|
||||||
|
if (start == true){
|
||||||
|
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 !");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package latice.model;
|
||||||
public enum Shape {
|
public enum Shape {
|
||||||
BIRD("bird", "B"),
|
BIRD("bird", "B"),
|
||||||
DOLPHIN("dolphin", "D"),
|
DOLPHIN("dolphin", "D"),
|
||||||
FLOWER("flower", "Fl"),
|
FLOWER("flower", "f"),
|
||||||
FEATHER("feather", "F"),
|
FEATHER("feather", "F"),
|
||||||
GECKO("gecko", "G"),
|
GECKO("gecko", "G"),
|
||||||
TURTLE("turtle", "T");
|
TURTLE("turtle", "T");
|
||||||
|
|
|
@ -30,7 +30,11 @@ public class Tile {
|
||||||
return this.shape.getStringShapeConsole();
|
return this.shape.getStringShapeConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position getPosition() {
|
public Integer getPositionRow() {
|
||||||
return this.position;
|
return this.position.getRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPositionColumn() {
|
||||||
|
return this.position.getColumn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
|
||||||
|
<GridPane alignment="CENTER" hgap="50.0" prefHeight="300.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.PlayerNameInputController">
|
||||||
|
<children>
|
||||||
|
<Label alignment="TOP_LEFT" text="Nom joueur 1 : ">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="35.0" />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Label>
|
||||||
|
<Label text="Nom joueur 2 : " GridPane.columnIndex="1">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="35.0" />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Label>
|
||||||
|
<TextField fx:id="nomJoueur1" GridPane.rowIndex="1" />
|
||||||
|
<TextField fx:id="nomJoueur2" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
<Button fx:id="validBtn" mnemonicParsing="false" onMouseClicked="#validBtnClicked" text="Valider" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="100.0" top="50.0" />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints />
|
||||||
|
<ColumnConstraints />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints maxHeight="39.99999389648437" minHeight="22.40001831054687" prefHeight="25.599999999999994" />
|
||||||
|
<RowConstraints maxHeight="25.59998168945313" minHeight="8.00000610351563" prefHeight="22.400000000000006" />
|
||||||
|
<RowConstraints maxHeight="25.59998168945313" minHeight="10.0" prefHeight="30.0" />
|
||||||
|
</rowConstraints>
|
||||||
|
</GridPane>
|
Loading…
Reference in New Issue