cleaned the source code 2

master
Mathis 2022-06-06 23:55:02 +02:00
parent 8aa26ca8de
commit 2ae745c638
7 changed files with 78 additions and 87 deletions

View File

@ -24,7 +24,6 @@ public class LaticeApplicationConsole {
for (Color color : Color.values()) { for (Color color : Color.values()) {
for (Shape shape : Shape.values()) { for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape); Tile tile = new Tile(color, shape);
System.out.println(color.getStringColor() + shape.getStringShape()+ ".png");
listOfTile.add(tile); listOfTile.add(tile);
@ -38,19 +37,14 @@ public class LaticeApplicationConsole {
Deck deck1 = new Deck(listOfTile); Deck deck1 = new Deck(listOfTile);
Deck deck2 = new Deck(listOfTile); Deck deck2 = new Deck(listOfTile);
Rack rack1 = new Rack(deck1);
Rack rack2 = new Rack(deck2);
Score scorePlayer1 = new Score();
Score scorePlayer2 = new Score();
Player player1 = new Player("player1", deck1); Player player1 = new Player("player1", deck1);
Player player2 = new Player("player2", deck2); Player player2 = new Player("player2", deck2);
System.out.println("-----------------");
GameBoard board = new GameBoard();
board.displayGameBoard();
System.out.println(Objects.equals(board.getGridBoard()[1][0], Tile.class)); GameBoard board = new GameBoard();
Scanner play = new Scanner(System.in); Scanner play = new Scanner(System.in);
Player player; Player player;
Boolean round; Boolean round;
@ -74,15 +68,17 @@ public class LaticeApplicationConsole {
while (round) { while (round) {
player.getRack().displayRack(); player.getRack().displayRack();
System.out.println("Vous avez " + player.getScore() +" points, que voulez-vous faire ?\n" System.out.println("Vous avez " + player.getScore() +" points, que voulez-vous faire ?\n"
+ " 1. Jouer une Tuile (à partir de la deuxième tuile jouée, cela coûtera 2 points)\n" + " 1. Jouer une Tuile\n"
+ " 2. Acheter une action supplémentaire\n" + " 2. Acheter une action supplémentaire(coûte 2 points)\n"
+ " 3. Changer le Rack et passer(coûte 3 points)\n" + " 3. Changer le Rack et passer(coûte 3 points)\n"
+ " 4. Passer\n"); + " 4. Passer\n");
System.out.print("Choix : "); System.out.print("Choix : ");
int choiceMenu = Integer.parseInt(play.next()); int choiceMenu = Integer.parseInt(play.next());
switch(choiceMenu) { switch(choiceMenu) {
case 1: if (freeTile) { case 1: if (freeTile) {
freeTile = false;
Boolean rulesCheck = false; Boolean rulesCheck = false;
while (rulesCheck == false) { while (rulesCheck == false) {
@ -102,18 +98,26 @@ public class LaticeApplicationConsole {
player.getRack().removeTile(tile); player.getRack().removeTile(tile);
board.displayGameBoard(); board.displayGameBoard();
}else {
System.out.println("Vous n'avez pas acheter une action pour jouer un autre tuile dans ce tour ! Veuillez en acheter une ou passer votre tour !");
} }
break; break;
case 2: case 2:
if (player.getScore()>=3) { 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 {
if (player.getScore()>=2) {
//Buy another action and remove 2 points from score //Buy another action and remove 2 points from score
player.Play(play, board, 0); player.Play(play, board, 0);
player.removePointsFromScore(2); player.removePointsFromScore(2);
freeTile = true;
}else { }else {
System.out.println("Il vous faut 2 points pour acheter une nouvelle action !"); System.out.println("Il vous faut 2 points pour acheter une nouvelle action !");
} }
}
break; break;

View File

@ -64,7 +64,7 @@ public class LaticeApplicationWindow extends Application {
//lists for tiles //lists for tiles
ArrayList<Tile> listRackTile; ArrayList<Tile> listRackTile;
ArrayList<Image> listOfTilesInRack; ArrayList<Image> listOfTilesInRack;
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); //ArrayList<Tile> listOfTile = new ArrayList<Tile>();
static StackPane rootLayout; static StackPane rootLayout;
public static int indexTileClicked; public static int indexTileClicked;
@ -260,21 +260,21 @@ public class LaticeApplicationWindow extends Application {
//Creating tiles //Creating tiles
for (Color color : Color.values()) { /*for (Color color : Color.values()) {
for (Shape shape : Shape.values()) { for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape); Tile tile = new Tile(color, shape);
listOfTile.add(tile); listOfTile.add(tile);
} }
} }*/
System.out.println("-----------------"); /*System.out.println("-----------------");
System.out.println("Notre Deck :"); System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile); Deck deck = new Deck(listOfTile);
System.out.println("-----------------"); System.out.println("-----------------");
Rack rack = new Rack(deck); Rack rack = new Rack(deck);
System.out.println("-----------------"); System.out.println("-----------------");*/
//Player //Player
@ -299,11 +299,11 @@ public class LaticeApplicationWindow extends Application {
changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); changeButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);
//Buy another action Button //Buy another action Button
Image buyActionImage = new Image("buyAction.png"); /*Image buyActionImage = new Image("buyAction.png");
ImageView buyActionView = new ImageView(buyActionImage); ImageView buyActionView = new ImageView(buyActionImage);
buyActionButton = new Button("Buy Action (2 points)", buyActionView); buyActionButton = new Button("Buy Action (2 points)", buyActionView);
buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH); buyActionButton.setPrefWidth(Constant.ACTION_BUTTONS_WIDTH);
buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT); buyActionButton.setPrefHeight(Constant.ACTION_BUTTONS_HEIGHT);*/
confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() { confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
//confirming the end of the round and switching round //confirming the end of the round and switching round
@ -320,12 +320,13 @@ public class LaticeApplicationWindow extends Application {
e.printStackTrace(); e.printStackTrace();
} }
confirmBtnClickedCount++; confirmBtnClickedCount++;
player.getRack().displayRack();
////// for the actual player //////
player.getRack().updateRack(); player.getRack().updateRack();
player.getRack().displayRack(); ////// changing player //////
//making names colored in red to make the players know which player's round is //making names colored in red to make the players know which player's round is
if (confirmBtnClickedCount%2 == 0) { if (confirmBtnClickedCount%2 == 0) {
playerFX.setFillName(Constant.realColor.BLACK); playerFX.setFillName(Constant.realColor.BLACK);
@ -339,12 +340,14 @@ public class LaticeApplicationWindow extends Application {
playerFX.setFillName(Constant.realColor.RED); playerFX.setFillName(Constant.realColor.RED);
} }
////// for the next player //////
isFreePlacement = true; isFreePlacement = true;
rackTileImage = player.getRack().createTileImage(); rackTileImage = player.getRack().createTileImage();
//Setting drag n drop on tiles
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackTileImage, player);
setDragnDropOnRectangles(rect, board, referee, player); setDragnDropOnRectangles(rect, board, referee, player);
rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/);
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackTileImage);
@ -378,7 +381,7 @@ public class LaticeApplicationWindow extends Application {
}); });
//With Image //Rack with Image
rackTileImage = player.getRack().createTileImage(); rackTileImage = player.getRack().createTileImage();
//Adding lists to Arraylists //Adding lists to Arraylists
@ -393,7 +396,7 @@ public class LaticeApplicationWindow extends Application {
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
////// for the actual player ////// ////// for the actual player //////
if (player.getScore() > 1) { if (player.getScore() >= 3) {
System.out.println("Changing Rack"); System.out.println("Changing Rack");
confirmBtnClickedCount++; confirmBtnClickedCount++;
player.getRack().changeRack(); player.getRack().changeRack();
@ -421,7 +424,7 @@ public class LaticeApplicationWindow extends Application {
//Setting drag n drop on tiles //Setting drag n drop on tiles
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackTileImage, player);
rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/);
setDragnDropOnRectangles(rect, board, referee, player); setDragnDropOnRectangles(rect, board, referee, player);
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackTileImage);
@ -434,16 +437,16 @@ public class LaticeApplicationWindow extends Application {
}); });
buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() { /*buyActionButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
gameInfoLabel.setText(player.getName() + ", you can now play another time !"); gameInfoLabel.setText(player.getName() + ", you can now play another time !");
} }
}); });*/
rackTileImage.getChildren().addAll(confirmButton, changeButton, buyActionButton); rackTileImage.getChildren().addAll(confirmButton, changeButton/*, buyActionButton*/);
setDragnDropOnRack(rackTileImage, player); setDragnDropOnRack(rackTileImage, player);
System.out.println(); System.out.println();
borderPane.setBottom(rackTileImage); borderPane.setBottom(rackTileImage);
@ -564,7 +567,7 @@ public class LaticeApplicationWindow extends Application {
}else { }else {
//if it's not the first round of the game //if it's not the first round of the game
//not removing the tile from the rack //putting the position of the gameboard's case on the tile from the rack
player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b)); player.getRack().getListRackTile().get(indexTileClicked).setPosition(new Position(a,b));
//verify if a tile is already placed //verify if a tile is already placed

View File

@ -60,8 +60,8 @@ public class PlayerNameInputController {
//setting player names //setting player names
String name1 = nomJoueur1.getText(); String name1 = nomJoueur1.getText();
String name2 = nomJoueur2.getText(); String name2 = nomJoueur2.getText();
System.out.println("nom des joueurs :");
System.out.println(nomJoueur1.getText()); System.out.println(nomJoueur1.getText());
System.out.println("nom des joueurs");
System.out.println(nomJoueur2.getText()); System.out.println(nomJoueur2.getText());
namePlayer1 = name1; namePlayer1 = name1;
namePlayer2 = name2; namePlayer2 = name2;

View File

@ -24,19 +24,6 @@ public class Player {
this(name, new Score(), deck, new Rack(deck)); this(name, new Score(), deck, new Rack(deck));
} }
/*public Player(Score score, Deck deck, Rack rack) {
this(namePlayer,score,deck,rack);
//Demande le nom du joueur
Scanner enterPlayerName = new Scanner(System.in);
System.out.println("Veuilez entrer votre nom :");
String namePlayer = enterPlayerName.next();
}*/
public String getName() { public String getName() {
return this.name; return this.name;
} }

View File

@ -111,12 +111,13 @@ public class Rules {
return this.moonRule(board, tile); return this.moonRule(board, tile);
}else { }else {
System.out.println("-----------------------------"); System.out.println("-----------------------------");
if (this.sunRule(board, tile)){ if (this.checkPositionRule(board, tile) == false ) {
player.addPointsToScore(2); System.out.println("Erreur ! la tuile ne peut pas être placé ici car il y a déjà une tuile placé");
} return false;
}else {
int nbr = this.neighborRule(board, tile); int nbr = this.neighborRule(board, tile);
if (nbr == 0) { 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 !"); 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; return false;
}else { }else {
@ -130,13 +131,18 @@ public class Rules {
System.out.println("Vous avez gagné 4 points"); System.out.println("Vous avez gagné 4 points");
player.addPointsToScore(4); player.addPointsToScore(4);
} }
if (this.sunRule(board, tile)){
player.addPointsToScore(2);
}
}
return true; return true;
} }
}
} }
} }
}

View File

@ -17,7 +17,7 @@ public class GameBoard {
for (int i = 0; i < DIMENSION; i++) { for (int i = 0; i < DIMENSION; i++) {
for (int j = 0; j < DIMENSION; j++) { for (int j = 0; j < DIMENSION; j++) {
System.out.print("|");
if (i == 4 && j == 4) { //Affiche la lune au centre du plateau if (i == 4 && j == 4) { //Affiche la lune au centre du plateau
this.gridBoard[i][j] = MOON; this.gridBoard[i][j] = MOON;
@ -39,9 +39,6 @@ public class GameBoard {
this.gridBoard[i][j] = BLUE; this.gridBoard[i][j] = BLUE;
} }
if (j == 8) {
System.out.println("|");
}
} }
} }
} }
@ -53,28 +50,28 @@ public class GameBoard {
System.out.print(i+1 + ". "); System.out.print(i+1 + ". ");
for (int j = 0; j < DIMENSION; j++) { for (int j = 0; j < DIMENSION; j++) {
System.out.print("|"); System.out.print("|");
if (i == 4 && j == 4) { //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) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if (i == j && (i <= 2 || i >= 6)) { //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) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if (i == DIMENSION-1-j && (i <= 2 || i >= 6)) { //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) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {
System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " "); System.out.print(" " + this.gridBoardTile[i][j].getShapeConsole() + this.gridBoardTile[i][j].getColorConsole() + " ");
} }
}else if ( ((i == 0 || i == 8)&& j == 4) || (i== 4 && (j == 0 || j == 8)) ) {//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) { if (this.gridBoardTile[i][j] == null) {
System.out.print(this.gridBoard[i][j]); System.out.print(this.gridBoard[i][j]);
}else { }else {

View File

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