a761485716
a761485716
2018-01-05 08:53

java斗地主把手中的牌的牌型显示出来

40
  • java
  • arraylist
  • hashmap

public static void main(String[] args) {
String[] pai = new String[] { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2" };
// String[] hs = new String[] { "♥", "♠", "♦", "♣" };
HashMap hj = new HashMap<>();
HashMap hy = new HashMap<>();
HashMap hb = new HashMap<>();

List<String> a = new ArrayList<String>();
for (int i = 0; i < pai.length; i++) {
    a.add(pai[i]);
    a.add(pai[i]);
    a.add(pai[i]);
    a.add(pai[i]);
}
a.add("大王");
a.add("小王");

Random rand = new Random();
String temp = null;
for (int k = 0; k < 100; k++) {
    int p = a.size();
    int l = rand.nextInt(p);
    int m = rand.nextInt(p);
    if (l == m)
        continue;
    {
        temp = a.get(l);
        a.set(l, a.get(m));
        a.set(m, temp);
    }
}
// Collections.shuffle(a);

List<String> j = new ArrayList<String>();
List<String> y = new ArrayList<String>();
List<String> b = new ArrayList<String>();
List<String> d = new ArrayList<String>();
for (int i = 0; i < a.size(); i++) {
    if (i >= a.size() - 3) {
        d.add(a.get(i));
    } else if (i % 3 == 0) {
        j.add(a.get(i));
    } else if (i % 3 == 1) {
        y.add(a.get(i));
    } else if (i % 3 == 2) {
        b.add(a.get(i));
    }
}
System.out.println(d);
System.out.println("甲" + j);
System.out.println("乙" + y);
System.out.println("丙" + b);
for (String str : j) {
    if (hj.containsKey(str)) {
        hj.put(str, hj.get(str) + 1);
    } else
        hj.put(str, 1);
}
System.out.println("j" + hj);

for (String str : y) {
    if (hy.containsKey(str)) {
        hy.put(str, hy.get(str) + 1);
    } else
        hy.put(str, 1);
}
System.out.println("y" + hy);

for (String str : b) {
    if (hb.containsKey(str)) {
        hb.put(str, hb.get(str) + 1);
    } else
        hb.put(str, 1);
}
System.out.println("b" + hb);

最好在我已经写出的代码上加代码,要显示出甲、乙、丙手牌的对子、三带、炸弹之类的牌型,求具体的代码!!!!!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答