-
Notifications
You must be signed in to change notification settings - Fork 2
/
Hand.java
78 lines (60 loc) · 1.62 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
package rookCore;
import java.util.ArrayList;
import java.util.Collections;
/**
* Created by ashton on 12/31/14.
*/
public class Hand implements CardHolderInterface {
ArrayList<Card> d;
public Hand() {
this.d = new ArrayList<Card>(8);
}
@Override
public void viewCards() {
}
public ArrayList<Card> getCards() {
return d;
}
@Override
public void addCard(Card c) {
this.d.add(c);
Collections.sort(d);
}
@Override
public Card releaseCardOut(int CardIndex) {
Card outCard = this.d.remove(CardIndex);
;
Collections.sort(d);
return outCard;
}
public void addCards(ArrayList<Card> cards) {
d.addAll(cards);
Collections.sort(d);
}
public ArrayList<Card> getCardsOfColor(Card.CARD_COLOR color) {
ArrayList<Card> returningCards = new ArrayList<Card>(1);
int fromIndex = -1, toIndex = -1;
for (int i = 0; i < d.size(); i++) {
if (d.get(i).cardColor == Card.CARD_COLOR.ROOK) {
returningCards.add(d.get(i));
}
if (d.get(i).cardColor == color) {
fromIndex = i;
break;
}
}
if (fromIndex == -1) {
return d;
}
toIndex = fromIndex;
for (int i = fromIndex; i < d.size(); i++) {
if (d.get(i).cardColor != color) {
toIndex = i - 1;
break;
}
toIndex = i;
}
returningCards.addAll(d.subList(fromIndex, toIndex + 1));
return returningCards;
}
}