ADD method removeTile and updateRack in Rack | ADD Player | UPDATE

LaticeApplicationConsole
master
Mathis 2022-05-19 20:45:30 +02:00
parent cf6049a4fe
commit 0124b6b3b0
4 changed files with 123 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package latice.application; package latice.application;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
import latice.model.Color; import latice.model.Color;
import latice.model.Deck; import latice.model.Deck;
@ -16,7 +17,7 @@ public class LaticeApplicationConsole {
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
System.out.println("Hello Latice !"); //System.out.println("Hello Latice !");
/* /*
for (Color color : Color.values()) { for (Color color : Color.values()) {
@ -70,27 +71,56 @@ public class LaticeApplicationConsole {
} }
System.out.println("-----------------"); 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 deck1 = new Deck(listOfTile);
Deck deck2 = new Deck(listOfTile); Deck deck2 = new Deck(listOfTile);
deck1.displayListTile();
System.out.println("-----------------");
Rack rack1 = new Rack(deck1); Rack rack1 = new Rack(deck1);
Rack rack2 = new Rack(deck2); Rack rack2 = new Rack(deck2);
Score scorePlayer1 = new Score(); Score scorePlayer1 = new Score();
Score scorePlayer2 = new Score(); Score scorePlayer2 = new Score();
Player player1 = new Player("player1", scorePlayer1); Player player1 = new Player("player1", scorePlayer1, deck1, rack1);
Player player2 = new Player("player2", scorePlayer2); Player player2 = new Player("player2", scorePlayer2, deck2, rack2);
System.out.println("-----------------"); System.out.println("-----------------");
GameBoard board = new GameBoard(); GameBoard board = new GameBoard();
board.displayGameBoard(); 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);
}
} }
} }

View File

@ -5,8 +5,10 @@ import java.util.Scanner;
public class Player { public class Player {
private final String name; private final String name;
private Score score; 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 //Demande le nom du joueur
Scanner enterPlayerName = new Scanner(System.in); Scanner enterPlayerName = new Scanner(System.in);
System.out.println("Veuilez entrer votre nom " + name + " :"); System.out.println("Veuilez entrer votre nom " + name + " :");
@ -14,10 +16,35 @@ public class Player {
this.name = namePlayer; this.name = namePlayer;
this.score = score; this.score = score;
this.deck = deck;
this.rack = rack;
} }
public String getName() { 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);
} }

View File

@ -20,16 +20,17 @@ public class Rack {
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()*((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); tile = (deck.getListTile()).get(index);
this.listRackTile.add(tile); this.listRackTile.add(tile);
// root.setCenter(imageView);
deck.getListTile().remove(index); 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");
@ -43,14 +44,51 @@ public class Rack {
this.listRackTile = listRackTile; 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() { public void displayRack() {
boolean success = false; boolean success = false;
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.getShape().getStringShapeConsole() + tile.getColor().getStringColorConsole()); System.out.print(", " + tile.getShapeConsole() + tile.getColorConsole());
}else { }else {
System.out.print(tile.getShape().getStringShapeConsole() + tile.getColor().getStringColorConsole()); System.out.print(tile.getShapeConsole() + tile.getColorConsole());
success = true; success = true;
} }
} }

View File

@ -18,10 +18,18 @@ public class Tile {
return this.color; return this.color;
} }
public String getColorConsole() {
return this.color.getStringColorConsole();
}
public Shape getShape() { public Shape getShape() {
return this.shape; return this.shape;
} }
public String getShapeConsole() {
return this.shape.getStringShapeConsole();
}
public Position getPosition() { public Position getPosition() {
return this.position; return this.position;
} }