-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hand.java
83 lines (67 loc) · 1.93 KB
/
Hand.java
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
72
73
74
75
76
77
78
79
80
81
82
83
import java.util.Collections;
import java.util.Vector;
public class Hand {
public Card[] cards;
private int cardsInHand = 2;
public Hand() {
cards = new Card[2];
for (int i = 0; i < cardsInHand; i++) {
cards[i] = Deck.getInstance().draw();
}
}
public Hand(Card[] cards) {
this.cards = cards;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Card) {
Card card = (Card) obj;
if (card.toString().equals(this.toString())) {
return true;
}
}
return false;
}
public Vector<Integer> getNumbers() {
Vector<Integer> numbers = new Vector<Integer>();
for (Card card : cards) {
numbers.add(card.getNumber());
}
numbers.addAll(Dealer.getInstance().getNumbersFromDealer());
Collections.sort(numbers);
// System.out.println(numbers);
return numbers;
}
public Vector<String> getSuits() {
Vector<String> suits = new Vector<String>();
for (Card card : cards) {
suits.add(card.getSuit());
}
suits.addAll(Dealer.getInstance().getSuitsFromDealer());
Collections.sort(suits);
// System.out.println(suits);
return suits;
}
public Card getHighCardFromPlayer() {
Card highCard = cards[0];
for (Card card : cards) {
if (card.getNumber() > highCard.getNumber()) {
highCard = card;
}
}
return highCard;
}
/** Returns the true if card 1 is the highest, false if otherwise */
public static boolean compareCards(int card1, int card2) {
if (card1 > card2) {
return true;
} else {
return false;
}
}
public void showCards() {
for (Card card : cards) {
System.out.println(card.toString());
}
}
}