-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullHouse.java
More file actions
84 lines (78 loc) · 2.91 KB
/
Copy pathFullHouse.java
File metadata and controls
84 lines (78 loc) · 2.91 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
80
81
82
83
84
/**
* It is a subclass of the Hand class and is used to model a hand of Full House in a Big two card game,
* i.e five cards with two having the same rank and three having another same rank
* It overrides the getType() and the isValid() and getTopCard() methods
* It also has a private instance variable first which marks if the three cards having the same rank appear earlier or not in a sorted deck
* @author Devang
*
*/
public class FullHouse extends Hand
{
private static final long serialVersionUID = 178749520333021015L;
private boolean first = true; // Shows if the three cards having the same rank appear earlier or not in a sorted deck
/**
* Constructor of the FullHouse class to initialise the player of the current hand and the cards played by the player
* It simply calls the super (Hand) class constructor
* @param player
* Use to specify the player of the current hand
* @param cards
* Used to specify the cards played in the current hand
*/
public FullHouse(CardGamePlayer player, CardList cards)
{
super(player,cards);
}
/**
* A getter method for returning a string specifying the type of this hand, i.e FullHouse.
* @return
* a string value specifying the type of hand, i.e FullHouse
*/
public String getType()
{
return "FullHouse";
}
/**
* An method for checking if this is a valid Full House, i.e five cards with two having the same rank and three having another same rank
* @return
* boolean value specifying if the hand being a FullHouse is valid or not
*/
public boolean isValid()
{
if (this.size() != 5)
return false;
Card c1 = this.getCard(0);
Card c2 = this.getCard(1);
Card c3 = this.getCard(2);
Card c4 = this.getCard(3);
Card c5 = this.getCard(4);
if (c3.getRank() == c4.getRank()) // Checking if the three cards having the same rank appear later in a sorted deck
first = false;
else
first = true;
if (first == true) // Condition if the three cards having the same rank appear first in a sorted deck
if((c1.getRank() == c2.getRank()) && (c2.getRank() == c3.getRank()) && (c3.getRank() != c4.getRank()) && (c4.getRank() == c5.getRank()))
return true;
if (first == false) // Condition if the three cards having the same rank appear later in a sorted deck
if((c1.getRank() == c2.getRank()) && (c2.getRank() != c3.getRank()) && (c3.getRank() == c4.getRank()) && (c4.getRank() == c5.getRank()))
return true;
return false;
}
/**
* A getter method for retrieving the top card of a Full House.
* @return
* the top card of the Full House
*/
public Card getTopCard()
{
Card c3 = this.getCard(2);
Card c4 = this.getCard(3);
if (c3.getRank() == c4.getRank()) // Comparing the 3rd and 4th card in the sorted hand
first = false;
else
first = true;
if(first == true) // Condition if the three cards having the same rank appear first in a sorted deck
return this.getCard(2);
else
return this.getCard(4);
}
}