扑克牌游戏比较花色时,不论返回-1还是1总会出现判断错误
以下是Compara类和测试方法中的比较大小方法,有没有大神能告诉下,为什么比较花色总是出现错误啊
//打印玩家的手牌
Collections.sort(player1.sp,new Compara());
System.out.println("玩家:"+name1+"的手牌为:");
for(Poker sp1:player1.sp){
System.out.println(sp1.hs+sp1.ds);
}
Collections.sort(player2.sp,new Compara());
System.out.println("玩家:"+name2+"的手牌为:");
for(Poker sp2:player2.sp){
System.out.println(sp2.hs+sp2.ds);
}
//打印玩家最大的手牌
//将手牌传递过去比较,用get(1)接收比较大得值,get(0)接收小值
Collections.sort(player1.sp,new Compara());
System.out.println("玩家"+player1.name+"最小的牌为:"+player1.sp.get(0).hs+player1.sp.get(0).ds);
System.out.println("玩家"+player1.name+"最大的牌为:"+player1.sp.get(1).hs+player1.sp.get(1).ds);
Collections.sort(player2.sp,new Compara());
System.out.println("玩家"+player2.name+"最小的牌为:"+player2.sp.get(0).hs+player2.sp.get(0).ds);
System.out.println("玩家"+player2.name+"最大的牌为:"+player2.sp.get(1).hs+player2.sp.get(1).ds);
//比较两个玩家最大手牌的大小,输出胜利者
List<Poker> maxsp=new ArrayList<Poker>();
maxsp.add(player1.sp.get(1));
maxsp.add(player2.sp.get(1));
Collections.sort(maxsp,new Compara());
if(maxsp.get(1).equals(player1.sp.get(1))){
System.out.println("胜利者为:"+name1+
"\n此时最大牌为:"+maxsp.get(1).hs+maxsp.get(1).ds);
}else{
System.out.println("胜利者为:"+name2+
"\n此时最大牌为:"+maxsp.get(1).hs+maxsp.get(1).ds);
}
}