-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
54 lines (45 loc) · 1.15 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
//********************************************************
// Player class for PokerTest
// by Pratishta Yerakala (py2211)
// Player class creates a player and has useful methods
// to get the hand and to sort the hand.
//
//********************************************************
import java.util.ArrayList;
import java.util.Collections;
public class Player {
private ArrayList<Card> hand;
private Deck newDeck;
// creates player
public Player() {
hand = new ArrayList<Card>();
newDeck = new Deck();
}
// deals five random cards from top of deck
public void playerHand() {
newDeck.shuffle();
for (int i = 0; i < 5; i++) {
addCard(newDeck.deal());
}
}
// adds the card c to the player's hand
public void addCard(Card c) {
hand.add(c);
}
// removes the card c from the player's hand
public void removeCard(Card c) {
hand.remove(c);
}
// method to return hand to use in other classes
public ArrayList<Card> getHand() {
return hand;
}
// method to return a card from hand array list
public Card getCard(int i) {
return hand.get(i);
}
// sorts ArrayList hand before evaluating
public void sort() {
Collections.sort(hand);
}
}