-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathPlayer.java
More file actions
57 lines (45 loc) · 1.27 KB
/
Player.java
File metadata and controls
57 lines (45 loc) · 1.27 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
package blackjack;
import java.util.Comparator;
import java.util.List;
public class Player {
private String name;
private Cards cards;
public boolean result;
public Player(String name){
this.name = name;
this.cards = new Cards();
}
public String getName() {
return this.name;
}
public Integer getSum() {
Integer result = 0;
cards.getCards()
.sort((c1, c2) -> c2.toInt().compareTo(c1.toInt()));
for(Card card : cards.getCards()) {
if (CardNumber.ACE.equals(card.getNumber())) {
if(result + 11 <= 21) {
result += 10;
}
}
result += card.toInt();
}
return result;
}
public Integer getCount() {
return this.cards.getSize();
}
public void add(Card card) {
cards.push(new Card(card));
}
public boolean isGreaterThan(int number) {
return getSum() >= number;
}
public String toStringList(int idx) {
List<String> collect = cards.getCards().stream().map(Card::toString).toList();
return String.join(", ", collect.subList(idx, collect.size()));
}
public String toStringList() {
return toStringList(0);
}
}