为了账号安全,请及时绑定邮箱和手机立即绑定

主要精力放扑克牌的比较规则上面了,是我功力不够吗~~~~(>_<)~~~~

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;	
    }	
    
}

正在回答

1 回答

你现在练的是外功,也就是招式,谈功力(内功)为时尚早,先将基本功打好。多看看别人写的代码,取长补短,事半功倍。实现功能只是第一步,优化永无止境。奔跑吧,少年!

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

主要精力放扑克牌的比较规则上面了,是我功力不够吗~~~~(>_<)~~~~

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信