-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
56 lines (45 loc) · 1.3 KB
/
Player.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
/**
* @author Sagar Shah
* Playing cards from: https://github.com/hayeah/playing-cards-assets
*/
import java.util.ArrayList;
public class Player {
private ArrayList<Card> hand = new ArrayList<>();
private ArrayList<ArrayList> books = new ArrayList<>();
public Player(){
}
public Player(ArrayList<Card> hand){
this.hand = hand;
}
public ArrayList<Card> getHand() {
return hand;
}
public void addToHand(ArrayList<Card> newCards){
for(int i=0; i<newCards.size(); i++){
hand.add(newCards.get(i));
}
}
public void addToHand(Card a){
hand.add(a);
}
public void createBooks(){
ArrayList<Card> currentBook = new ArrayList<>();
int currentRank = -1;
int currentTally = 0; //taly for current rank
for(int i=0; i<hand.size(); i++) {
currentRank = hand.get(i).getRank();
for (int y = 0; y < hand.size(); y++) {
if (hand.get(y).getRank() == currentRank) {
currentBook.add(hand.get(y));
currentTally++;
}
}
if(currentBook.size()==4){
books.add(currentBook);
}
}
}
public ArrayList<ArrayList> getBooks(){
return books;
}
}