public class Card implements Comparable<Card> {
String pattern; //花色
String figure; //点数
public Card(String pattern, String figure) {
this.pattern = pattern;
this.figure = figure;
}
/**
* 比较对象:当前扑克牌与传入的扑克牌
* 比较内容:点数、花色
* 比较步骤:
* 对比二者的点数,
* 1.若点数相同,
* (1)若当前扑克牌的花色较大,则返回正整数。
* (2)若当前扑克牌的花色较小,则返回负整数。
* 2.若点数不同,
* (1)若当前扑克牌的点数较大,则返回正整数。
* (2)若当前扑克牌的点数较大,则返回负整数。
*/
@Override
public int compareTo(Card c) {
if(this.figure.equals("10")) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else if((c.figure.equals("J")) || (c.figure.equals("Q")) || (c.figure.equals("K")) || (c.figure.equals("A"))) {
return -1;
}else {
return 1;
}
}else if(this.figure.equals("Q")) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else if((c.figure.equals("K")) || (c.figure.equals("A"))) {
return -1;
}else {
return 1;
}
}else if(this.figure.equals("A")) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else {
return 1;
}
}else if((!(this.figure.equals("J"))) && (!(this.figure.equals("K")))) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else if(c.figure.equals("10")) {
return -1;
}else {
return this.figure.compareTo(c.figure);
}
}else if(this.figure.equals("J")) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else if(c.figure.equals("A")) {
return -1;
}else {
return this.figure.compareTo(c.figure);
}
}else if(this.figure.equals("K")) {
if(c.figure.equals(this.figure)) {
if(this.pattern.equals("方片")) {
return -1;
}else if((this.pattern.equals("梅花")) && (!(c.pattern.equals("方片")))) {
return -1;
}else if((this.pattern.equals("红桃")) && (c.pattern.equals("黑桃"))) {
return -1;
}else {
return 1;
}
}else if(c.figure.equals("Q")) {
return 1;
}else if(c.figure.equals("A")) {
return -1;
}else {
return this.figure.compareTo(c.figure);
}
}
return 0;
}
}