标题: 斗地主代码,排序带地主牌和底牌添加 [打印本页] 作者: 郝永 时间: 2017-4-14 22:25 标题: 斗地主代码,排序带地主牌和底牌添加 写了一下午,出了BUG,找了好一会,亮出来分享一下!
public class DDZ {
static HashMap<Integer, Card> hm = new HashMap<>();
static ArrayList<Integer> list = new ArrayList<>();
static {
hm.put(1, new Card("大", "☺"));// ♠♥♣♦
hm.put(2, new Card("小", "☺"));
list.add(1);
list.add(2);
String[] arr = { "♠", "♥", "♣", "♦" };
String[] arr1 = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
int i = 3;
for (String s : arr1) {
for (String st : arr) {
list.add(i);
hm.put(i++, new Card(st, s));
}
}
}
public static void main(String[] args) {
Collections.shuffle(list);
Random r = new Random();
int d = r.nextInt(52);// 获取list的一个角标
System.out.println("随机的list的一个角标:" + d);
System.out.println("扑克牌:" + hm);
int dzj = list.get(d);
System.out.println("地主牌的键:" + dzj);