package com.yigege.poker;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Poker implements Comparable<Poker>{
private String hs;
private String ds;
private static final int CARDNUM = 52;
private static final int SINGLECARDNUM = 13;
private static final int COLORNUM = 4;
private static final List<String> Color = Arrays.asList("黑桃", "红桃", "梅花", "方块");
// private static final List<String> Colors = Arrays.asList("方块", "草花", "红桃","黑桃");
private static final List<String> Number = Arrays.asList("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A");
public String getHs() {
return hs;
}
public String getDs() {
return ds;
}
public Poker(){
}
public Poker(String hs, String ds){
this.hs = hs;
this.ds = ds;
}
// public Poker(){
//
// }
public static List<Poker> cardCreate(){
List<Poker> card = new ArrayList<>();
for (int i=0; i<CARDNUM; ++i){
String newValue = null;
String newColor = null;
int tmp = i % SINGLECARDNUM;
newValue = Number.get(tmp);
// System.out.println(tmp);
tmp = i % COLORNUM;
newColor = Color.get(tmp);
//cardList中添加扑克牌
card.add(new Poker(newColor, newValue));
}
return card;
}
@Override
public String toString() {
return "[" + Color + " " + Number + "]";
}
@Override
public int compareTo(Poker o) {
if (Number.indexOf(this.ds) == Number.indexOf(o.ds)) {
return Integer.valueOf(Color.indexOf(this.hs)).compareTo(Integer.valueOf(Color.indexOf(o.hs)));
} else {
return Integer.valueOf(Number.indexOf(this.ds)).compareTo(Integer.valueOf(Number.indexOf(o.ds)));
}
}
}
还有代码呢