-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathParticipant.java
More file actions
72 lines (59 loc) · 1.9 KB
/
Participant.java
File metadata and controls
72 lines (59 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package Domain;
import java.util.ArrayList;
import java.util.List;
public class Participant {
private String name;
List<TrumpCard> ParticipantCardList = new ArrayList<>();
public int winningPrice = 0 ;
public boolean isBlackJack = false ;
public Participant(String name, List<TrumpCard> ParticipantCardList) {
this.name = name;
this.ParticipantCardList = ParticipantCardList;
}
public void addParticipantCardList(TrumpCard trumpCard) {
this.ParticipantCardList.add(trumpCard);
}
public int getParticipantScore() {
int score = ParticipantCardList.stream().map(TrumpCard::getCardScore).mapToInt(i->i).sum();
if (aceCount()){
return checkAce(score);
}
return score;
}
public boolean aceCount(){
return ParticipantCardList.stream().anyMatch(a -> a.getCardNumber() == 1);
}
public int checkAce(int score){
// if ParticipantCardList.cardNumber == 0 이 있다면
if (score <= 11){
return score - 1 + 11 ;
}
return score ;
}
public String getCardName(){
String cardInfos = "";
for(TrumpCard trumpCard : ParticipantCardList){
if (!trumpCard.isHiddenCard) {
cardInfos += getOneCardName(trumpCard);
cardInfos += ", ";
}
}
return cardInfos ;
}
public String getOneCardName(TrumpCard trumpCard){
String[] cardInfo = {"0", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
return cardInfo[trumpCard.cardNumber] + trumpCard.cardShape;
}
public String getName() {
return this.name;
}
public boolean isBurst(){
if(getParticipantScore() >= 21){
return true;
}
return false;
}
public List<TrumpCard> getParticipantCardList() {
return ParticipantCardList;
}
}