-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullHouse.java
72 lines (63 loc) · 1.8 KB
/
FullHouse.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
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
/**
* Fullhouse class is a subclass of FiveHand which model a fullhouse hand
* and implement the method in FiveHand
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public class FullHouse extends FiveHand{
// public constructor of Fullhouse
public FullHouse(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Check whether the hand is a valid fullhouse
* @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 == 2 & count2 == 3){
return true;
}
if (count1 == 3 & count2 == 2){
return true;
}
}
}
return false;
}
/**
* Return the topcard
* @return Card
*/
public Card getTopCard(){
this.sort();
if (this.getCard(0).getRank()==this.getCard(2).getRank()){
return this.getCard(2);
}
else if (this.getCard(2).getRank()==this.getCard(4).getRank()){
return this.getCard(4);
}
return null;
}
/**
* Return type of hand
* @return String
*/
public String getType(){
return "Full House";
}
}