105 lines
3.4 KiB
Java
105 lines
3.4 KiB
Java
package de.hs_mannheim.informatik.blackjack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
|
|
public class Karte {
|
|
|
|
private String farbe;
|
|
private String karte;
|
|
|
|
|
|
|
|
Karte(String farbe, String karte){
|
|
this.farbe=farbe;
|
|
this.karte=karte;
|
|
|
|
}
|
|
|
|
public String toString(){
|
|
return farbe + " " + karte;
|
|
}
|
|
|
|
public int getPunkte(ArrayList<Karte> hand){
|
|
|
|
int counter = 0;
|
|
for(int i = 0; i<hand.size(); i++){
|
|
if(hand.get(i).karte.equals("Ass"))
|
|
counter ++;
|
|
}
|
|
|
|
if(karte.equals("Bube")||karte.equals("Dame")||karte.equals("König"))
|
|
return 10;
|
|
else if(karte.equals("Ass")&&counter==1) {
|
|
int entscheidung = 0;
|
|
for(int i = 0; i<hand.size(); i++) {
|
|
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
|
entscheidung += 10;
|
|
} else if (!hand.get(i).karte.equals("Ass")) {
|
|
entscheidung += Integer.parseInt(hand.get(i).karte);
|
|
}
|
|
}
|
|
if (entscheidung<=10)
|
|
return 11;
|
|
else
|
|
return 1;
|
|
}else if(karte.equals("Ass")&&counter==2) {
|
|
int entscheidung = 0;
|
|
int counterAss = 0;
|
|
for(int i = 0; i<hand.size(); i++) {
|
|
|
|
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
|
entscheidung += 10;
|
|
} else if (!hand.get(i).karte.equals("Ass")) {
|
|
entscheidung += Integer.parseInt(hand.get(i).karte);
|
|
} else if(counterAss<1) {
|
|
entscheidung += 1;
|
|
counterAss ++;
|
|
}
|
|
}
|
|
if (entscheidung<=10)
|
|
return 11;
|
|
else
|
|
return 1;
|
|
}else if(karte.equals("Ass")&&counter==3) {
|
|
int entscheidung = 0;
|
|
int counterAss = 0;
|
|
for(int i = 0; i<hand.size(); i++) {
|
|
|
|
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
|
entscheidung += 10;
|
|
} else if (!hand.get(i).karte.equals("Ass")) {
|
|
entscheidung += Integer.parseInt(hand.get(i).karte);
|
|
} else if(counterAss<2) {
|
|
entscheidung += 1;
|
|
counterAss ++;
|
|
}
|
|
}
|
|
if (entscheidung<=10)
|
|
return 11;
|
|
else
|
|
return 1;
|
|
}else if(karte.equals("Ass")&&counter==4) {
|
|
int entscheidung = 0;
|
|
int counterAss = 0;
|
|
for(int i = 0; i<hand.size(); i++) {
|
|
|
|
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
|
entscheidung += 10;
|
|
} else if (!hand.get(i).karte.equals("Ass")) {
|
|
entscheidung += Integer.parseInt(hand.get(i).karte);
|
|
} else if(counterAss<3) {
|
|
entscheidung += 1;
|
|
counterAss ++;
|
|
}
|
|
}
|
|
if (entscheidung<=10)
|
|
return 11;
|
|
else
|
|
return 1;
|
|
}
|
|
else
|
|
return Integer.parseInt(karte);
|
|
}
|
|
}
|