diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index 0c981c6..5c2291b 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -1,13 +1,14 @@ package latice.application; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Scanner; -import javafx.scene.image.Image; import latice.model.Color; import latice.model.Deck; +import latice.model.GameBoard; +import latice.model.Player; import latice.model.Rack; +import latice.model.Score; import latice.model.Shape; import latice.model.Tile; @@ -16,9 +17,9 @@ public class LaticeApplicationConsole { ArrayList listOfTile = new ArrayList(); - System.out.println("Hello Latice !"); - + //System.out.println("Hello Latice !"); + /* for (Color color : Color.values()) { for (Shape shape : Shape.values()) { Tile tile = new Tile(color, shape); @@ -39,9 +40,87 @@ public class LaticeApplicationConsole { Rack rack = new Rack(deck); System.out.println("-----------------"); deck.displayListTile(); - + + System.out.println("-----------------"); + GameBoard board = new GameBoard(); + board.displayGameBoard(); + System.out.println("-----------------"); + board.setGridBoard(" NV ", 4, 4); + board.displayGameBoard(); + System.out.println("-----------------"); + Score scorePlayer1 = new Score(); + Score scorePlayer2 = new Score(); + Player player1 = new Player("player1", scorePlayer1); + Player player2 = new Player("player2", scorePlayer2); + + System.out.println(player1.getName() + " a " + scorePlayer1.getScore() +" points"); + System.out.println(player2.getName() + " a " + scorePlayer2.getScore() +" points"); + + rack.displayRack(); + + */ + + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + + listOfTile.add(tile); + + } + } + + System.out.println("-----------------"); + //System.out.println("Notre Deck :"); + //Deck deck1 = new Deck(listOfTile); + //Deck deck2 = new Deck(listOfTile); + //deck1.displayListTile(); + System.out.println("-----------------"); + //Rack rack1 = new Rack(deck1); + //Rack rack2 = new Rack(deck2); + //Score scorePlayer1 = new Score(); + //Score scorePlayer2 = new Score(); + //Player player1 = new Player("player1", scorePlayer1); + //Player player2 = new Player("player2", scorePlayer2); + + System.out.println("-----------------"); + //GameBoard board = new GameBoard(); + //board.displayGameBoard(); + System.out.println("-----------------"); + + //System.out.println(player1.getName() + " a " + scorePlayer1.getScore() +" points"); + //System.out.println(player2.getName() + " a " + scorePlayer2.getScore() +" points"); + //rack1.displayRack(); + System.out.println("Hello Latice !"); + System.out.println("-----------------"); + + Deck deck1 = new Deck(listOfTile); + Deck deck2 = new Deck(listOfTile); + Rack rack1 = new Rack(deck1); + Rack rack2 = new Rack(deck2); + + Score scorePlayer1 = new Score(); + Score scorePlayer2 = new Score(); + Player player1 = new Player("player1", scorePlayer1, deck1, rack1); + Player player2 = new Player("player2", scorePlayer2, deck2, rack2); + + System.out.println("-----------------"); + GameBoard board = new GameBoard(); + board.displayGameBoard(); + + + Scanner play = new Scanner(System.in); + + for(int i = 0; i < 10; i++) { + + player1.Play(play,board); + player2.Play(play,board); + + + + } } } diff --git a/src/main/java/latice/model/Color.java b/src/main/java/latice/model/Color.java index 7c3fe17..bf0a682 100644 --- a/src/main/java/latice/model/Color.java +++ b/src/main/java/latice/model/Color.java @@ -1,20 +1,26 @@ package latice.model; public enum Color { - YELLOW("y"), - NAVYBLUE("n"), - RED("r"), - MAGENTA("m"), - GREEN("g"), - TURQUOISE("t"); //TODO find what is the color turchese, and write it's color code + YELLOW("y", "Y"), + NAVYBLUE("n", "N"), + RED("r", "R"), + MAGENTA("m", "M"), + GREEN("g", "G"), + TURQUOISE("t", "T"); private String stringColor; + private String stringColorConsole; - Color(String stringColor) { + Color(String stringColor, String stringColorConsole) { this.stringColor = stringColor; + this.stringColorConsole = stringColorConsole; } public String getStringColor() { return this.stringColor; } + + public String getStringColorConsole() { + return this.stringColorConsole; + } } diff --git a/src/main/java/latice/model/GameBoard.java b/src/main/java/latice/model/GameBoard.java new file mode 100644 index 0000000..9da6f67 --- /dev/null +++ b/src/main/java/latice/model/GameBoard.java @@ -0,0 +1,85 @@ +package latice.model; + +public class GameBoard { + private Integer DIMENSION = 9; + public static final String SUN = " SU "; + public static final String MOON = " MO "; + private String[][] gridBoard; + + public GameBoard() { + this.gridBoard = new String[DIMENSION][DIMENSION]; + + for (int i = 0; i < DIMENSION; i++) { + for (int j = 0; j < DIMENSION; j++) { + System.out.print("|"); + if (i == 4 && j == 4) { //Affiche la lune au centre du plateau + + this.gridBoard[i][j] = MOON; + + + }else if (i == j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('\') de soleil + + this.gridBoard[i][j] = SUN; + + }else if (i == DIMENSION-1-j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('/') de soleil + + this.gridBoard[i][j] = SUN; + + }else if ( ((i == 0 || i == 8)&& j == 4) || (i== 4 && (j == 0 || j == 8)) ) {//Affiche les soleils au mileu de chaque coté ('+') + + this.gridBoard[i][j] = SUN; + + }else { + this.gridBoard[i][j] = " "; + } + + if (j == 8) { + System.out.println("|"); + } + } + } + } + + public void displayGameBoard() { + + for (int i = 0; i < DIMENSION; i++) { + for (int j = 0; j < DIMENSION; j++) { + System.out.print("|"); + if (i == 4 && j == 4) { //Affiche la lune au centre du plateau + + System.out.print(this.gridBoard[i][j]); + + }else if (i == j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('\') de soleil + + System.out.print(this.gridBoard[i][j]); + + }else if (i == DIMENSION-1-j && (i <= 2 || i >= 6)) { //Affiche la diagonale ('/') de soleil + + System.out.print(this.gridBoard[i][j]); + + }else if ( ((i == 0 || i == 8)&& j == 4) || (i== 4 && (j == 0 || j == 8)) ) {//Affiche les soleils au mileu de chaque coté ('+') + + System.out.print(this.gridBoard[i][j]); + + }else { + System.out.print(this.gridBoard[i][j]); + } + + if (j == 8) { + System.out.println("|"); + } + } + } + } + + public String[][] getGridBoard() { + return gridBoard; + } + + public void setGridBoard(String value, Integer x, Integer y) { + this.gridBoard[x][y] = value; + } + + + +} diff --git a/src/main/java/latice/model/Player.java b/src/main/java/latice/model/Player.java new file mode 100644 index 0000000..11dfacd --- /dev/null +++ b/src/main/java/latice/model/Player.java @@ -0,0 +1,60 @@ +package latice.model; + +import java.util.Scanner; + +public class Player { + private final String name; + private Score score; + private Rack rack; + 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.score = score; + this.deck = deck; + this.rack = rack; + } + + public String getName() { + return this.name; + } + + public Integer getScore() { + return this.score.getScore(); + } + + public void Play(Scanner play, GameBoard board) { + System.out.println("c'est à votre tour de jouer " + this.name +"!"); + if (this.getScore() == 0) { + + System.out.println("Vous avez " + this.getScore() + " point"); + + }else { + System.out.println("Vous avez " + this.getScore() + " points"); + + } + + System.out.print("Quel tuile voulez-vous jouez ? "); + this.rack.displayRack(); + String tileToPlay = play.next(); + System.out.print("Sur quelle ligne, voulez-vous placer la tuile ?"); + int row = Integer.parseInt(play.next()); + System.out.print("Sur quelle colonne, voulez-vous placer la tuile ?"); + int column = Integer.parseInt(play.next()); + board.setGridBoard(" "+tileToPlay+" ", row, column); + this.rack.removeTile(tileToPlay); + + board.displayGameBoard(); + + this.rack.updateRack(); + + + } + + +} diff --git a/src/main/java/latice/model/Position.java b/src/main/java/latice/model/Position.java new file mode 100644 index 0000000..d92c44a --- /dev/null +++ b/src/main/java/latice/model/Position.java @@ -0,0 +1,21 @@ +package latice.model; + +public class Position { + private final Integer row; + private final Integer column; + + public Position(Integer row, Integer column) { + this.row = row; + this.column = column; + } + + public Integer getRow() { + return row; + } + + public Integer getColumn() { + return column; + } + + +} diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java index cdb7806..e2913aa 100644 --- a/src/main/java/latice/model/Rack.java +++ b/src/main/java/latice/model/Rack.java @@ -10,40 +10,93 @@ import javafx.scene.layout.HBox; import javafx.scene.text.Text; public class Rack { - private static ArrayList listRackTile = new ArrayList(); - private static ArrayList rackTileImage = new ArrayList(); + private ArrayList listRackTile = new ArrayList(); + private ArrayList rackTileImage = new ArrayList(); + private Deck deck; public Rack(Deck deck) { + this.deck = deck; - Image image = new Image("laticePlateau.png"); - ImageView imageView = new ImageView(image); Tile tile; System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); for (int i = 0; i < 5; i++) { - int index = (int)(Math.random()*((deck.getListTile()).size()-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); + + tile = (this.deck.getListTile()).get(index); + this.listRackTile.add(tile); + this.deck.getListTile().remove(index); + + - tile = (deck.getListTile()).get(index); - listRackTile.add(tile); - // root.setCenter(imageView); - deck.getListTile().remove(index); } - System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); + System.out.println("Il y a dans le rack : " + this.listRackTile.size() + " valeurs"); } - public static ArrayList getListRackTile() { - return listRackTile; + public ArrayList getListRackTile() { + return this.listRackTile; } public void setListRackTile(ArrayList listRackTile) { this.listRackTile = listRackTile; } + + + public void updateRack() { + + Tile tile; + + for (int i = 0; i < 5-this.listRackTile.size() ; 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 removeTile(String stringTile) { + int count = 0; + int index = -1; + System.out.println("taille : " + this.listRackTile.size()); + for (Tile tile : this.listRackTile) { + System.out.println(count++); + if (stringTile.equals(tile.getShapeConsole() + tile.getColorConsole())) { + index = this.listRackTile.indexOf(tile); + System.out.println(index); + System.out.println("tuile supprimé avec succès"); + } + + } + + if (index != -1) { + this.listRackTile.remove(index); + } + System.out.println("taille : " + this.listRackTile.size()); + + } + + public void displayRack() { + boolean success = false; + System.out.print("rack : "); + for (Tile tile : this.listRackTile) { + if (success) { + System.out.print(", " + tile.getShapeConsole() + tile.getColorConsole()); + }else { + System.out.print(tile.getShapeConsole() + tile.getColorConsole()); + success = true; + } + } + System.out.println(); + } @@ -77,7 +130,7 @@ public class Rack { } - public static ArrayList getRackTileImage() { + public ArrayList getRackTileImage() { return rackTileImage; } diff --git a/src/main/java/latice/model/Rules.java b/src/main/java/latice/model/Rules.java new file mode 100644 index 0000000..152c2bf --- /dev/null +++ b/src/main/java/latice/model/Rules.java @@ -0,0 +1,11 @@ +package latice.model; + +public class Rules { + private static boolean START = true; + + public Rules() { + // TODO Auto-generated constructor stub + } + + +} diff --git a/src/main/java/latice/model/Score.java b/src/main/java/latice/model/Score.java new file mode 100644 index 0000000..e9267f2 --- /dev/null +++ b/src/main/java/latice/model/Score.java @@ -0,0 +1,19 @@ +package latice.model; + +public class Score { + private Integer score; + + public Score() { + this.score = 0; + } + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + +} diff --git a/src/main/java/latice/model/Shape.java b/src/main/java/latice/model/Shape.java index e6d7da5..442ef31 100644 --- a/src/main/java/latice/model/Shape.java +++ b/src/main/java/latice/model/Shape.java @@ -1,20 +1,26 @@ package latice.model; public enum Shape { - BIRD("bird"), - DOLPHIN("dolphin"), - FLOWER("flower"), - FEATHER("feather"), - GECKO("gecko"), - TURTLE("turtle"); + BIRD("bird", "B"), + DOLPHIN("dolphin", "D"), + FLOWER("flower", "Fl"), + FEATHER("feather", "F"), + GECKO("gecko", "G"), + TURTLE("turtle", "T"); private String stringShape; + private String stringShapeConsole; - Shape(String stringShape) { + Shape(String stringShape, String stringShapeConsole) { this.stringShape = stringShape; + this.stringShapeConsole = stringShapeConsole; } public String getStringShape() { return this.stringShape; } + + public String getStringShapeConsole() { + return this.stringShapeConsole; + } } diff --git a/src/main/java/latice/model/Tile.java b/src/main/java/latice/model/Tile.java index b2ff117..0c98546 100644 --- a/src/main/java/latice/model/Tile.java +++ b/src/main/java/latice/model/Tile.java @@ -3,17 +3,34 @@ package latice.model; public class Tile { private final Color color; private final Shape shape; + private Position position; public Tile(Color color, Shape shape) { this.color = color; this.shape = shape; } + public void setPosition(Position position) { + this.position = position; + } + public Color getColor() { return this.color; } + public String getColorConsole() { + return this.color.getStringColorConsole(); + } + public Shape getShape() { return this.shape; } + + public String getShapeConsole() { + return this.shape.getStringShapeConsole(); + } + + public Position getPosition() { + return this.position; + } }