好友
阅读权限10
听众
最后登录1970-1-1
|
java斗地主
代码如下:
public class Splendid {
public static void main(String[] args) {
String[] arr1 = { "♣", "♦", "♥", "♠" };
String[] arr2 = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", };
ArrayList<String> list = new ArrayList<>();
HashMap<Integer, String> map = new HashMap<>();
ArrayList<Integer> key = new ArrayList<>();
ArrayList<Integer> play1 = new ArrayList<>();
ArrayList<Integer> play2 = new ArrayList<>();
ArrayList<Integer> play3 = new ArrayList<>();
ArrayList<Integer> dipai = new ArrayList<>();
for (int i = 0; i < arr2.length; i++) {
for (int j = 0; j < arr1.length; j++) {
list.add(arr1[j] + arr2[i]);
}
}
list.add("小王");
list.add("大王");
// System.out.println(list);
for (int i = 0; i < list.size(); i++) {
key.add(i);
}
Collections.shuffle(key);
for (int i = 0; i < list.size(); i++) {
map.put(i, list.get(i));
if (i>list.size()-4) {
dipai.add(key.get(i));
} else if (i % 3 == 0) {
play1.add(key.get(i));
} else if (i % 3 == 1) {
play2.add(key.get(i));
} else {
play3.add(key.get(i));
}
}
lookpai(map,play1);
lookpai(map,play2);
lookpai(map,play3);
lookpai(map,dipai);
}
private static void lookpai(HashMap<Integer, String> map, ArrayList<Integer> play) {
Collections.sort(play);
for (int i = 0; i <play.size(); i++) {
String string = map.get(play.get(i));
System.out.print(string);
}
System.out.println();
}
|
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|