Merge branch 'added_Deck_and_Rack_classes' into 'master'

Added deck and rack classes

See merge request odabasioglu1/latice!1
master
Odabasioglu Cemal 2022-04-24 12:06:48 +00:00
commit 37a8ad922c
4 changed files with 80 additions and 36 deletions

View File

@ -1,49 +1,39 @@
package latice.application; package latice.application;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import latice.model.Color; import latice.model.Color;
import latice.model.Deck;
import latice.model.Rack;
import latice.model.Shape; import latice.model.Shape;
import latice.model.Tile; import latice.model.Tile;
public class LaticeApplicationConsole { public class LaticeApplicationConsole {
public static void main(String[] args) { public static void main(String[] args) {
Tile blueBird = new Tile(Color.BLUE, Shape.BIRD); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
Tile greenLeaf = new Tile(Color.GREEN, Shape.LEAF);
Tile redFlower = new Tile(Color.RED, Shape.FLOWER);
ArrayList<Tile> rackPlayer1 = new ArrayList<Tile>();
ArrayList<Tile> rackPlayer2 = new ArrayList<Tile>();
int tilesNumber = 3;
ArrayList<Tile> tiles =new ArrayList<Tile>(Arrays.asList(blueBird, greenLeaf, redFlower)); System.out.println("Hello Latice !");
System.out.println("Hello Latice ! " + blueBird.getShape() + blueBird.getColor());
System.out.println("Hello Latice ! " + greenLeaf.getShape() + greenLeaf.getColor());
System.out.println("Hello Latice ! " + redFlower.getShape() + redFlower.getColor());
System.out.println("Hello Latice ! " + tiles.get(0).getShape() + tiles.get(0).getColor());
//------------------------------Tiles attribution----------------------------------- for (Color color : Color.values()) {
Random random = new Random(); for (Shape shape : Shape.values()) {
for(int i=0; i<=tilesNumber; i++) { Tile tile = new Tile(color, shape);
if(! tiles.isEmpty()) {
int randomNumber = random.nextInt(tiles.size()); listOfTile.add(tile);
if(i%2 == 0) {
rackPlayer1.add(tiles.get(randomNumber));
System.out.println(rackPlayer1.get(0).getColor().toString() + rackPlayer1.get(0).getShape().toString());
} else {
rackPlayer2.add(tiles.get(randomNumber));
System.out.println(rackPlayer2.get(0).getColor().toString() + rackPlayer2.get(0).getShape().toString());
}
tiles.remove(randomNumber);
System.out.println(randomNumber);
System.out.println(rackPlayer1);
System.out.println(rackPlayer2);
}
} }
}
System.out.println("-----------------");
System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile);
deck.displayListTile();
System.out.println("-----------------");
Rack rack = new Rack(deck);
System.out.println("-----------------");
deck.displayListTile();
} }

View File

@ -0,0 +1,26 @@
package latice.model;
import java.util.ArrayList;
public class Deck {
private ArrayList<Tile> deckTile = new ArrayList<Tile>();
public Deck(ArrayList<Tile> deckTile) {
this.deckTile = deckTile;
}
public void displayListTile() {
for (Tile tile : deckTile) {
System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape());
}
}
public ArrayList<Tile> getListTile() {
return this.deckTile;
}
}

View File

@ -0,0 +1,28 @@
package latice.model;
import java.util.ArrayList;
public class Rack {
private ArrayList<Tile> listRackTile = new ArrayList<Tile>();
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.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
}

View File

@ -1,8 +1,8 @@
package latice.model; package latice.model;
public class Tile { public class Tile {
Color color; private final Color color;
Shape shape; private final Shape shape;
public Tile(Color color, Shape shape) { public Tile(Color color, Shape shape) {
this.color = color; this.color = color;
@ -10,10 +10,10 @@ public class Tile {
} }
public Color getColor() { public Color getColor() {
return color; return this.color;
} }
public Shape getShape() { public Shape getShape() {
return shape; return this.shape;
} }
} }