-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuad.java
More file actions
70 lines (63 loc) · 1.76 KB
/
Copy pathQuad.java
File metadata and controls
70 lines (63 loc) · 1.76 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
/**
* 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 Quad extends FiveHand{
// Public constructor of Quad
public Quad(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Check whether the hand is a valid quad
* @return boolean
*/
public boolean isValid(){
int temp1, temp2 = -1, count1 = 5, count2 = 0;
if (!this.isEmpty()){
if (this.size()== 5){
temp1 = this.getCard(0).getRank();
for (int i = 1; i < 5; i++){
if (this.getCard(i).getRank() != temp1){
if (temp2 == -1){
temp2 = this.getCard(i).getRank();
}
count1 -= 1;
}
if (this.getCard(i).getRank() == temp2){
count2 += 1;
}
}
if (count1 == 1 & count2 == 4){
return true;
}
if (count1 == 4 & count2 == 1){
return true;
}
}
}
return false;
}
/**
* Return type of hand
* @return String
*/
public String getType(){
return "Quad";
}
/**
* Return the topcard
* @return Card
*/
public Card getTopCard(){
this.sort();
if (this.getCard(0).getRank()==this.getCard(3).getRank()){
return this.getCard(3);
}
else if (this.getCard(1).getRank()==this.getCard(4).getRank()){
return this.getCard(4);
}
return null;
}
}