为什么比较大小结果不理想 不管什么都是平局。
public int compareTo(Pukepai arg0) {
if(this.getcardPoints()==arg0.getcardPoints()){
return this.getCardSuit().compareTo(cardSuit);
}
else{
return this.getCardPoints().compareTo(cardPoints);
}
}
}
public class Game {
private List<Play> playList;
private List<Pukepai> pukepaiList;
public Game(){
playList=new ArrayList<Play>();
pukepaiList=new ArrayList<Pukepai>();
}
//初始化牌(创建牌)
public void Chuangjianpai(){
System.out.println("-----生成扑克牌-----");
String[] cardSuits={"黑桃","红桃","梅花","方片"};
String[] cardPoints={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
for(int i=0;i<cardSuits.length;i++){
for(int j=0;j<cardPoints.length;j++){
pukepaiList.add(new Pukepai(cardPoints[j],cardSuits[i]));
}
}
System.out.println("创建成功");
System.out.println(pukepaiList);
}
//洗牌
public void Xipai(){
System.out.println("---开始洗牌----");
Collections.shuffle(pukepaiList);
System.out.println("---洗牌结束----");
}
//创建玩家
public void ChuangjianPlayer(){
Scanner ID=new Scanner(System.in);
System.out.println("请输入第一位玩家ID");
String id1=ID.next();
System.out.println("请输入第二位玩家ID");
String id2 =ID.next();
Scanner NAME =new Scanner(System.in);
System.out.println("请输入第一位玩家NAME");
String name1=NAME.next();
System.out.println("请输入第二位玩家NAME");
String name2=NAME.next();
System.out.println("成功添加玩家一:"+id1+name1);
System.out.println("成功添加玩家二:"+id2+name2);
playList.add(new Play(name1, id1));
playList.add(new Play(name2, id2));
}
//发牌
public void Fapai(){
System.out.println("---开始发牌----");
for(int i=0;i<2;i++){
for(int j=0;j<playList.size();j++){
System.out.println("玩家:"+playList.get(j).getName()+"拿牌");
playList.get(j).setPukepai(pukepaiList.get(0));
pukepaiList.remove(0);
}
}
System.out.println("---发牌结束----");
}
//比大小(游戏开始)
public void StartGame(){
System.out.println("---游戏开始----");
for(int i=0;i<playList.size();i++){
Collections.sort(playList.get(i).pukepaiList);
System.out.println("玩家"+playList.get(i).getName()+"最大手牌为:"+
playList.get(i).pukepaiList.get(1));
}
//接比较结果放于daxiao变量
int daxiao=playList.get(0).pukepaiList.get(1).compareTo(playList.get(1).pukepaiList.get(1));
System.out.println(daxiao);
if(daxiao>0){
String name1=playList.get(0).getName();
System.out.println("玩家"+name1+"获胜");
}
else if(daxiao<0){
String name2=playList.get(1).getName();
System.out.println("玩家"+name2+"获胜");
}else{
System.out.println("平局");
}
}