-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStraightFlush.java
More file actions
56 lines (49 loc) · 1.58 KB
/
Copy pathStraightFlush.java
File metadata and controls
56 lines (49 loc) · 1.58 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
import java.util.*;
/**
* Quad class is a subclass of FiveHand which model a quad hand
* and implement the method in FiveHand
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public class StraightFlush extends FiveHand{
// Public constructor of straightflush
public StraightFlush(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Check whether the hand is a valid straight flush
* @return boolean
*/
public boolean isValid(){
if (!this.isEmpty()){
if (this.size()== 5){
int[] rank = new int[5];
int temp;
for (int i = 0; i < 5; i ++){
temp = this.getCard(i).getRank();
if (temp < 2){
temp += 13;
}
rank[i] = temp;
}
Arrays.sort(rank);
for (int i = 0; i < 4; i++){
if (rank[i+1] - rank[i] != 1){
return false;
}
}
if (this.size() == 5 && this.getCard(0).getSuit() == this.getCard(1).getSuit() & this.getCard(1).getSuit() == this.getCard(2).getSuit() & this.getCard(2).getSuit() == this.getCard(3).getSuit() & this.getCard(3).getSuit() == this.getCard(4).getSuit()){
return true;
}
}
}
return false;
}
/**
* Return the type of the hand
* @return String
*/
public String getType(){
return "Straight Flush";
}
}