-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlayer.java
More file actions
61 lines (49 loc) · 1.17 KB
/
Copy pathPlayer.java
File metadata and controls
61 lines (49 loc) · 1.17 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
58
59
60
61
/*
* author: alex torres
* this class is the player class. this player class has a hand that will store cards.
*/
public class Player {
//hand of player that will holds the cards
private Hand hand;
//constructor that receives an hand
public Player(Hand h) {
hand = h;
}
//returns hand
public Hand getHand() {
return hand;
}
public int getHandSize() {
return hand.getSize();
}
//takes card from hand base on index
public Card removeCard(int index) {
Card tempCard = hand.removeCard(index);
return tempCard;
}
//add card to hand
public void addCard(Card card ) {
hand.addCard(card);
}
//this method will check if the hand has a pair and will get rid of it
public void removePairs() {
for (int i = 0; i < (hand.getSize() - 2); i++ ) {
Card c1 = hand.getCard(i);
for (int j =1; j < (hand.getSize() - 1); j++) {
Card c2 = hand.getCard(j);
if (Card.compareByValue.compare(c1, c2) == 0) {
hand.removeCard(i);
hand.removeCard(j);
System.out.println("pair removed");
}
continue;
}
continue;
}
}
//toString
@Override
public String toString() {
return hand.toString();
}
}