-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigTwoCard.java
More file actions
41 lines (38 loc) · 826 Bytes
/
Copy pathBigTwoCard.java
File metadata and controls
41 lines (38 loc) · 826 Bytes
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
/**
* The BigTwoCard class is a subclass of Card and is to model
* the card of the BigTwo game.
*
* @author Chan Yuk Yin (UID: 3035786574)
*/
public class BigTwoCard extends Card{
// public constructor of the BigTwoCard class
public BigTwoCard(int suit, int rank){
super(suit, rank);
}
/**
* Override method that compare two Card in BigTwo way
* @param card
* @return int
*/
public int compareTo(Card card){
int this_rank = this.rank;
int card_rank = card.rank;
if (this.rank < 2){
this_rank += 13;
}
if (card.rank < 2){
card_rank += 13;
}
if (this_rank > card_rank) {
return 1;
} else if (this_rank < card_rank) {
return -1;
} else if (this.suit > card.suit) {
return 1;
} else if (this.suit < card.suit) {
return -1;
} else {
return 0;
}
}
}