48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
|
package Uni.semester03.BlackJack;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collections;
|
||
|
|
||
|
public class Kartenstapel {
|
||
|
private ArrayList<Karte> karten;
|
||
|
|
||
|
protected Kartenstapel() {
|
||
|
karten = createStapel();
|
||
|
}
|
||
|
|
||
|
public Karte getKarte() {
|
||
|
Karte neachsteKarte = karten.getFirst();
|
||
|
karten.removeFirst();
|
||
|
return neachsteKarte;
|
||
|
}
|
||
|
|
||
|
public int getZahlUebrigerKarten() {
|
||
|
return karten.size();
|
||
|
}
|
||
|
|
||
|
public static ArrayList<Karte> createStapel() {
|
||
|
ArrayList<Karte> stapel = new ArrayList<>();
|
||
|
|
||
|
String[] farben = {"Karo", "Herz", "Pik", "Kreuz"};
|
||
|
String[] karten = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "ASS"};
|
||
|
|
||
|
for (String farbe : farben) {
|
||
|
for (String karte : karten) {
|
||
|
Karte neueKarte = new Karte(farbe, karte);
|
||
|
stapel.add(neueKarte);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Collections.shuffle(stapel);
|
||
|
return stapel;
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
String ausgabe = "Kartenstapel: \n";
|
||
|
for (Karte karte : karten) {
|
||
|
ausgabe += karte.toString() + "\n";
|
||
|
}
|
||
|
return ausgabe;
|
||
|
}
|
||
|
}
|