-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlush.java
More file actions
84 lines (77 loc) · 1.67 KB
/
Copy pathFlush.java
File metadata and controls
84 lines (77 loc) · 1.67 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Arrays;
/**
* This class is a subclass of the Hand class, and are used to model a hand of Flush.
* It overrides getTopCard,isValid and getType method that it inherits from Hand class.
*
* @author Pranav Talwar
*
*/
@SuppressWarnings("serial")
public class Flush extends Hand{
/**
* Constructor for Flush type hand. Calls the constructor of Hand superclass.
*
* @param player Player who plays the hand
* @param cards List of card played by the player
*/
public Flush(CardGamePlayer player, CardList cards) {
super(player, cards);
}
/* (non-Javadoc)
* Returns the top card of the hand.
*
* @see Hand#getTopCard()
*/
public Card getTopCard() {
int[] handranks = new int[5];
for(int i=0;i<5;i++) {
if(this.getCard(i).getRank()==0) {
handranks[i] = 13;
}
else if(this.getCard(i).getRank()==1) {
handranks[i] = 14;
}
else {
handranks[i] = this.getCard(i).getRank();
}
}
Arrays.sort(handranks);
if(handranks[4]>=13) {
handranks[4]-=13;
}
int returnIndex = 0;
for(int i=1;i<5;i++) {
if(this.getCard(i).getRank() == handranks[4]) {
returnIndex = i;
}
}
return this.getCard(returnIndex);
}
/* (non-Javadoc)
* Checks whether the hand is a Flush.
*
* @see Hand#isValid()
*/
public boolean isValid() {
if(this.size() == 5) {
boolean flag = true;
int suit = this.getCard(0).getSuit();
for(int i=1;i<this.size();i++) {
if(suit != this.getCard(i).getSuit()) {
flag = false;
break;
}
}
return flag;
}
return false;
}
/* (non-Javadoc)
* Returns type of string.
*
* @see Hand#getType()
*/
public String getType() {
return "Flush";
}
}