-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSingle.java
62 lines (55 loc) · 1.32 KB
/
Single.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
/**
* This is a subclass of class Hand.
* It is used to model a hand of single in a Big Two card Game.
* @author HAORAN
* @since 2016/10/15
* @version 1.0
*
*/
public class Single extends Hand {
/**
* Defaulted generated serialVersionUID
*/
private static final long serialVersionUID = -4767109893813557115L;
public Single(CardGamePlayer player, CardList cards) {
super(player, cards);
// TODO Auto-generated constructor stub
}
/**
* A method for checking if this is a valid hand.
*/
public boolean isValid() {
// TODO Auto-generated method stub
if (size() == 1)
return true;
else
return false;
}
/**
* This method return the type of the hand of cards.
* If valid return "Single" else return null.
*/
String getType() {
if (this.isValid())
return "Single";
else
return null;
}
/**
* This method retrieves the top card of this hand of cards.
* @return card
*/
public Card getTopCard() {
return this.getCard(0);
}
/**
* This method judge whether this hand will beat that specified hand or not.
* @return true for yes, false otherwise.
*/
public boolean beats(Hand hand) {
if (hand.getType() == "Single" && this.getTopCard().compareTo(hand.getTopCard()) > 0)
return true;
else
return false;
}
}