-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiveHand.java
More file actions
56 lines (49 loc) · 2 KB
/
Copy pathFiveHand.java
File metadata and controls
56 lines (49 loc) · 2 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
/**
* The FiveHand class is a subclass of Hand which model a hand of 5 cards
* It gives template of the beats method for any hand with 5 cards
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public abstract class FiveHand extends Hand{
// Public constructor of FiveHand
public FiveHand(CardGamePlayer player, CardList cards){
super(player, cards);
}
/**
* Method that check whether this hand beats a certain hand
* @param hand
* @return boolean
*/
public boolean beats(Hand hand){
// Return false if it is not valid or not the same size
if (!this.isValid() || !hand.isValid() || (this.size() != hand.size())){
return false;
}
BigTwoCard ThisTopCard = (BigTwoCard) this.getTopCard();
BigTwoCard TopCard = (BigTwoCard) hand.getTopCard();
// Return true if same type and both are valid and this beats the sepcified hand
if (this.size() == hand.size() & this.getType() == hand.getType() & ThisTopCard.compareTo(TopCard) == 1 & this.isValid() & hand.isValid()){
return true;
}
// String array that store the rankings of hand with 5 cards
String[] FiveCards = new String[]{"Straight", "Flush", "Full House", "Quad", "Straight Flush"};
// compare if it is not same 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;
}
public abstract boolean isValid(); //abstract method for check valid hand
public abstract String getType(); //abstract method for getting the Type of hand
}