-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuad.java
69 lines (61 loc) · 1.63 KB
/
Quad.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
/**
* This class is a subclass of the Hand class, and are used to model a hand of Quad.
* It overrides getTopCard,isValid and getType method that it inherits from Hand class.
*
* @author Pranav Talwar
*
*/
@SuppressWarnings("serial")
public class Quad extends Hand{
/**
* Constructor for the Quad type hand. Calls the constructor of Hand super class.
*
* @param player Player who plays the hand
* @param cards List of card played by the player
*/
public Quad(CardGamePlayer player, CardList cards) {
super(player, cards);
}
/* (non-Javadoc)
* Returns the top card of the hand
* @see Hand#getTopCard()
*/
public Card getTopCard() {
this.sort();
if(this.getCard(1).getRank() == this.getCard(4).getRank()) {
return this.getCard(4);
}
else if(this.getCard(0).getRank() == this.getCard(3).getRank()) {
return this.getCard(3);
}
return null;
}
/* (non-Javadoc)
* Checks whether the hand is a Quad.
*
* @see Hand#isValid()
*/
public boolean isValid() {
if(this.size() == 5) {
this.sort();
if((this.getCard(0).getRank() == this.getCard(1).getRank()) && (this.getCard(1).getRank() == this.getCard(2).getRank()) && (this.getCard(2).getRank() == this.getCard(3).getRank())) {
return true;
}
else if((this.getCard(1).getRank() == this.getCard(2).getRank()) && (this.getCard(2).getRank() == this.getCard(3).getRank()) && (this.getCard(3).getRank() == this.getCard(4).getRank())) {
return true;
}
else {
return false;
}
}
return false;
}
/* (non-Javadoc)
* Returns type of string.
*
* @see Hand#getType()
*/
public String getType() {
return "Quad";
}
}