-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStraight.java
More file actions
52 lines (46 loc) · 1.24 KB
/
Copy pathStraight.java
File metadata and controls
52 lines (46 loc) · 1.24 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
import java.util.*;
/**
* Straight class is a subclass of FiveHand which model a straight hand
* and implement the method in FiveHand
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public class Straight extends FiveHand{
public Straight(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Check whether the hand is a valid straight or not
* @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;
}
}
return true;
}
}
return false;
}
/**
* Return type of hand
* @return String
*/
public String getType(){
return "Straight";
}
}