From dba464f4ef3448478369850a4e67191f35830b64 Mon Sep 17 00:00:00 2001 From: mathi Date: Tue, 19 Apr 2022 23:19:52 +0200 Subject: [PATCH 1/3] UPDATE Tile and LaticeApplicationConsole classes --- .../application/LaticeApplicationConsole.java | 30 +++++++++++++++++++ src/main/java/latice/model/Tile.java | 12 ++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index 9859a2a..5f94db2 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -1,8 +1,38 @@ package latice.application; +import java.util.ArrayList; + +import latice.model.Color; +import latice.model.Deck; +import latice.model.Shape; +import latice.model.Tile; + public class LaticeApplicationConsole { public static void main(String[] args) { + + ArrayList listOfTile = new ArrayList(); + System.out.println("Hello Latice !"); + + + for (Color color : Color.values()) { + for (Shape shape : Shape.values()) { + Tile tile = new Tile(color, shape); + System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); + listOfTile.add(tile); + + } + } + + + System.out.println("Notre Deck :"); + Deck deck = new Deck(listOfTile); + deck.getListTile(); + System.out.println("-----------------"); + + + + } } diff --git a/src/main/java/latice/model/Tile.java b/src/main/java/latice/model/Tile.java index 7b06526..b2ff117 100644 --- a/src/main/java/latice/model/Tile.java +++ b/src/main/java/latice/model/Tile.java @@ -1,11 +1,19 @@ package latice.model; public class Tile { - Color color; - Shape shape; + private final Color color; + private final Shape shape; public Tile(Color color, Shape shape) { this.color = color; this.shape = shape; } + + public Color getColor() { + return this.color; + } + + public Shape getShape() { + return this.shape; + } } From 431e9759e960bd743ca8182f05fea9f16b542bd8 Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 19 Apr 2022 23:24:10 +0200 Subject: [PATCH 2/3] WIP add Deck and Rack classes --- src/main/java/latice/model/Deck.java | 20 ++++++++++++++++++++ src/main/java/latice/model/Rack.java | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/latice/model/Deck.java create mode 100644 src/main/java/latice/model/Rack.java diff --git a/src/main/java/latice/model/Deck.java b/src/main/java/latice/model/Deck.java new file mode 100644 index 0000000..df59de1 --- /dev/null +++ b/src/main/java/latice/model/Deck.java @@ -0,0 +1,20 @@ +package latice.model; + +import java.util.ArrayList; + +public class Deck { + private ArrayList deckTile = new ArrayList(); + + public Deck(ArrayList deckTile) { + this.deckTile = deckTile; + } + + public void getListTile() { + for (Tile tile : deckTile) { + System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); + } + + } + + +} diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java new file mode 100644 index 0000000..f4af62f --- /dev/null +++ b/src/main/java/latice/model/Rack.java @@ -0,0 +1,21 @@ +package latice.model; + +import java.util.ArrayList; + +public class Rack { + private ArrayList listRackTile = new ArrayList(); + + public Rack(ArrayList deck) { + for (int i = 0; i < 5; i++) { + int index = (int)(Math.random()*(deck.size()-0+1)+0); + listRackTile.add(deck.get(index)); + System.out.println("l'indice de la tuile ajouté au rack est : " + index + " qui est la tuile " + deck.get(index)); + + } + + + } +} + + +//(int)(Math.random()*(max-min+1)+min); \ No newline at end of file From c4ed8e583244faab5fb9d13d5e06610921b0fbc5 Mon Sep 17 00:00:00 2001 From: mathi Date: Sat, 23 Apr 2022 16:05:32 +0200 Subject: [PATCH 3/3] ADD Deck and Rack classes with UPDATE LaticeApplicationConsole --- .../application/LaticeApplicationConsole.java | 11 ++++++---- src/main/java/latice/model/Deck.java | 8 ++++++- src/main/java/latice/model/Rack.java | 21 ++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index 5f94db2..ad11012 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import latice.model.Color; import latice.model.Deck; +import latice.model.Rack; import latice.model.Shape; import latice.model.Tile; @@ -18,18 +19,20 @@ public class LaticeApplicationConsole { for (Color color : Color.values()) { for (Shape shape : Shape.values()) { Tile tile = new Tile(color, shape); - System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); + listOfTile.add(tile); } } - + System.out.println("-----------------"); System.out.println("Notre Deck :"); Deck deck = new Deck(listOfTile); - deck.getListTile(); + deck.displayListTile(); System.out.println("-----------------"); - + Rack rack = new Rack(deck); + System.out.println("-----------------"); + deck.displayListTile(); diff --git a/src/main/java/latice/model/Deck.java b/src/main/java/latice/model/Deck.java index df59de1..39b4449 100644 --- a/src/main/java/latice/model/Deck.java +++ b/src/main/java/latice/model/Deck.java @@ -9,12 +9,18 @@ public class Deck { this.deckTile = deckTile; } - public void getListTile() { + public void displayListTile() { for (Tile tile : deckTile) { System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); } } + + public ArrayList getListTile() { + return this.deckTile; + } + + } diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java index f4af62f..36f0e60 100644 --- a/src/main/java/latice/model/Rack.java +++ b/src/main/java/latice/model/Rack.java @@ -5,17 +5,24 @@ import java.util.ArrayList; public class Rack { private ArrayList listRackTile = new ArrayList(); - public Rack(ArrayList deck) { + public Rack(Deck deck) { + 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.size()-0+1)+0); - listRackTile.add(deck.get(index)); - System.out.println("l'indice de la tuile ajouté au rack est : " + index + " qui est la tuile " + deck.get(index)); + int index = (int)(Math.random()*((deck.getListTile()).size()-0+1)+0); //(int)(Math.random()*(max-min+1)+min); + listRackTile.add((deck.getListTile()).get(index)); + System.out.println("l'indice de la tuile ajouté au rack est : " + index + + " qui est la tuile : couleur = " + (deck.getListTile()).get(index).getColor() + + " forme = " + (deck.getListTile()).get(index).getShape()); + deck.getListTile().remove(index); } - + System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); } + + + // TODO add method(s) javafx + } - -//(int)(Math.random()*(max-min+1)+min); \ No newline at end of file