Merge branch 'added_Deck_and_Rack_classes' into 'master'
Added deck and rack classes See merge request odabasioglu1/latice!1master
commit
cff5a97d93
|
@ -1,49 +1,39 @@
|
|||
package latice.application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import latice.model.Color;
|
||||
import latice.model.Deck;
|
||||
import latice.model.Rack;
|
||||
import latice.model.Shape;
|
||||
import latice.model.Tile;
|
||||
|
||||
public class LaticeApplicationConsole {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Tile blueBird = new Tile(Color.BLUE, Shape.BIRD);
|
||||
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> listOfTile = new ArrayList<Tile>();
|
||||
|
||||
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-----------------------------------
|
||||
Random random = new Random();
|
||||
for(int i=0; i<=tilesNumber; i++) {
|
||||
if(! tiles.isEmpty()) {
|
||||
int randomNumber = random.nextInt(tiles.size());
|
||||
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);
|
||||
}
|
||||
for (Color color : Color.values()) {
|
||||
for (Shape shape : Shape.values()) {
|
||||
Tile tile = new Tile(color, shape);
|
||||
|
||||
listOfTile.add(tile);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
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;
|
||||
|
@ -10,10 +10,10 @@ public class Tile {
|
|||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
return this.shape;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue