-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStraight.java
46 lines (44 loc) · 1.09 KB
/
Straight.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
/**
* This class is used to model a hand of Straight
*
* @author Chan Sze Wing
*
*/
public class Straight extends Hand {
/**
* Building a hand of Straight with a player and their chosen list of cards
*
* @param player the index of player
* @param cards the list of selected cards
*/
public Straight(CardGamePlayer player, CardList cards) {
super(player, cards);
}
/**
* Check if the hand is a valid Straight hand
*
* @return true if the hand is Straight, otherwise false
*/
public boolean isValid() {
if (this.size() == 5) {
this.sort();
int temp = this.getCard(0).getRank();
for (int i = 1; i < this.size(); i++) {
if (this.getCard(i).getRank() != (++temp % 13)) {
return false;
}
}
return true;
} else {
return false;
}
}
/**
* Return the hand's type
*
* @return the string "Straight"
*/
public String getType() {
return "Straight";
}
}