-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlush.java
More file actions
79 lines (70 loc) · 2.59 KB
/
Copy pathFlush.java
File metadata and controls
79 lines (70 loc) · 2.59 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
71
72
73
74
75
76
77
78
79
/**
* Flush class is a subclass of FiveHand which model a flush hand
* and implement the method in FiveHand
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public class Flush extends FiveHand{
public Flush(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Overrided beats method that compare hand in Flush way
* @param hand
* @return boolean
*/
public boolean beats(Hand hand){
// return false if it is not valid
if (!this.isValid() || !hand.isValid() || (this.size() != hand.size())){
return false;
}
int ThisSuit = this.getCard(0).getSuit(), HandSuit = hand.getCard(0).getSuit();
int check = 0; //checker of beats 0: false 1: true
BigTwoCard ThisTopCard = (BigTwoCard) this.getTopCard();
BigTwoCard TopCard = (BigTwoCard) hand.getTopCard();
// compare hands if they have the same type
if (ThisSuit > HandSuit || (ThisSuit == HandSuit & ThisTopCard.compareTo(TopCard) == 1)){
check = 1;
}
if (this.size() == hand.size() & this.getType() == hand.getType() & check == 1 & this.isValid() & hand.isValid()){
return true;
}
// String array that store the rankings of hands with 5 cards
String[] FiveCards = new String[]{"Straight", "Flush", "Full House", "Quad", "Straight Flush"};
// compare hands with 5 cards which have different type
if (this.size() == hand.size() & this.size() == 5 & this.isValid() & hand.isValid()){
int ThisBeat = -1, HandBeat = -1;
for (int i = 0; i < FiveCards.length; i++){
if (FiveCards[i] == this.getType()){
ThisBeat = i;
}
if (FiveCards[i] == hand.getType()){
HandBeat = i;
}
}
if (ThisBeat > HandBeat){
return true;
}
}
return false;
}
/**
* Check whether this hand is a valid flush
* @return boolean
*/
public boolean isValid(){
if (!this.isEmpty()){
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 type of this hand
* @return String
*/
public String getType(){
return "Flush";
}
}