diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index eb17cd3..5c2291b 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -1,6 +1,7 @@ package latice.application; import java.util.ArrayList; +import java.util.Scanner; import latice.model.Color; import latice.model.Deck; @@ -16,7 +17,7 @@ public class LaticeApplicationConsole { ArrayList listOfTile = new ArrayList(); - System.out.println("Hello Latice !"); + //System.out.println("Hello Latice !"); /* for (Color color : Color.values()) { @@ -70,27 +71,56 @@ public class LaticeApplicationConsole { } System.out.println("-----------------"); - System.out.println("Notre Deck :"); + //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); - 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); + 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(); - System.out.println("-----------------"); - System.out.println(player1.getName() + " a " + scorePlayer1.getScore() +" points"); - System.out.println(player2.getName() + " a " + scorePlayer2.getScore() +" points"); - rack1.displayRack(); - + + 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/Player.java b/src/main/java/latice/model/Player.java index 0279cdc..60d7441 100644 --- a/src/main/java/latice/model/Player.java +++ b/src/main/java/latice/model/Player.java @@ -5,8 +5,10 @@ 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) { + 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 + " :"); @@ -14,10 +16,35 @@ public class Player { this.name = namePlayer; this.score = score; + this.deck = deck; + this.rack = rack; } public String getName() { - return name; + 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 +"!"); + 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(deck); + + } diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java index 1bb35a7..3063828 100644 --- a/src/main/java/latice/model/Rack.java +++ b/src/main/java/latice/model/Rack.java @@ -20,16 +20,17 @@ public class Rack { 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()*(((deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min); tile = (deck.getListTile()).get(index); - this.listRackTile.add(tile); - - // root.setCenter(imageView); - deck.getListTile().remove(index); + + + + + } System.out.println("Il y a dans le rack : " + this.listRackTile.size() + " valeurs"); @@ -43,14 +44,51 @@ public class Rack { this.listRackTile = listRackTile; } + + public void updateRack(Deck deck) { + + Tile tile; + + for (int i = 0; i < 5-this.listRackTile.size() ; i++) { + int index = (int)(Math.random()*( ((deck.getListTile()).size()-1)-0+1)+0); //(int)(Math.random()*(max-min+1)+min); + + tile = (deck.getListTile()).get(index); + this.listRackTile.add(tile); + 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.getShape().getStringShapeConsole() + tile.getColor().getStringColorConsole()); + System.out.print(", " + tile.getShapeConsole() + tile.getColorConsole()); }else { - System.out.print(tile.getShape().getStringShapeConsole() + tile.getColor().getStringColorConsole()); + System.out.print(tile.getShapeConsole() + tile.getColorConsole()); success = true; } } diff --git a/src/main/java/latice/model/Tile.java b/src/main/java/latice/model/Tile.java index 5ded38a..0c98546 100644 --- a/src/main/java/latice/model/Tile.java +++ b/src/main/java/latice/model/Tile.java @@ -18,10 +18,18 @@ public class Tile { 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; }