90 lines
2.4 KiB
Java
90 lines
2.4 KiB
Java
package de.hs_mannheim.informatik.domain;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class Hand {
|
|
|
|
private ArrayList<Karte> hand = new ArrayList<>();
|
|
|
|
|
|
public Hand(Karte... karte){
|
|
for(int i = 0; i<karte.length; i++){
|
|
hand.add(karte[i]);
|
|
}
|
|
|
|
}
|
|
public Hand(Kartenstapel ks){
|
|
hand.add(ks.getKarte());
|
|
hand.add(ks.getKarte());
|
|
}
|
|
|
|
public String toString(){
|
|
String hand = "";
|
|
for (int i = 0; i<this.hand.size(); i++){
|
|
hand += this.hand.get(i).toString();
|
|
hand += " ";
|
|
}
|
|
return hand;
|
|
}
|
|
|
|
public int getPunkte(){
|
|
int ergebnis = 0;
|
|
int counterAss = 0;
|
|
|
|
for(int i = 0; i<hand.size(); i++){
|
|
if(hand.get(i).karte.equals("Ass"))
|
|
counterAss++;
|
|
}
|
|
|
|
for(int i = 0; i<hand.size(); i++){
|
|
ergebnis += hand.get(i).getPunkte();
|
|
}
|
|
|
|
if(counterAss==1) {
|
|
for (int i = 0; i < hand.size(); i++) {
|
|
if (hand.get(i).karte.equals("Ass") && ergebnis <= 10) {
|
|
ergebnis += 11;
|
|
} else if(hand.get(i).karte.equals("Ass"))
|
|
ergebnis += 1;
|
|
}
|
|
} else if(counterAss==2){
|
|
for (int i = 0; i < hand.size(); i++) {
|
|
if (hand.get(i).karte.equals("Ass") && ergebnis <= 9) {
|
|
ergebnis += 11;
|
|
} else if(hand.get(i).karte.equals("Ass"))
|
|
ergebnis += 1;
|
|
}
|
|
} else if(counterAss==3){
|
|
for (int i = 0; i < hand.size(); i++) {
|
|
if (hand.get(i).karte.equals("Ass") && ergebnis <= 8) {
|
|
ergebnis += 11;
|
|
} else if(hand.get(i).karte.equals("Ass"))
|
|
ergebnis += 1;
|
|
}
|
|
} else if(counterAss==4){
|
|
for (int i = 0; i < hand.size(); i++) {
|
|
if (hand.get(i).karte.equals("Ass") && ergebnis <= 7) {
|
|
ergebnis += 11;
|
|
} else if(hand.get(i).karte.equals("Ass"))
|
|
ergebnis += 1;
|
|
}
|
|
}
|
|
|
|
|
|
return ergebnis;
|
|
}
|
|
|
|
public boolean isBlackJack(){
|
|
if(hand.size()==2&&getPunkte()==21)
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
public void addKarte(Kartenstapel ks){
|
|
hand.add(ks.getKarte());
|
|
}
|
|
|
|
}
|