//准备数据 String[] flower = {"♣","♥","♦","♠"}; String[] number = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"}; String[] king = {"大王","小王"}; //存牌 HashMap<Integer,String> list = new HashMap<>(); int sum = 0; for (int i = 0; i < number.length; i++) { for (int j = 0; j < flower.length; j++) { list.put(sum,number[i] + flower[j]); sum++; } } for(String value : king) { list.put(sum,value); sum++; } LinkedList<Integer> linkedList = new LinkedList<>(); for (int i = 0; i < list.size(); i++) { linkedList.add(i); } //洗牌 Collections.shuffle(linkedList); //发牌 int[] bottomPaper = {linkedList.get(linkedList.size() - 3) , linkedList.get(linkedList.size() - 2) ,linkedList.get(linkedList.size() - 1) }; TreeSet<Integer> user1 = new TreeSet<>(); TreeSet<Integer> user2 = new TreeSet<>(); TreeSet<Integer> user3 = new TreeSet<>(); //给每个用户发牌 for (int i = 0; i < linkedList.size() - 3; i++) { if (i % 3 == 0) { user1.add(linkedList.get(i)); }else if (i % 3 == 1) { user2.add(linkedList.get(i)); }else { user3.add(linkedList.get(i)); } } //遍历底牌 for (Integer key : bottomPaper) { System.out.print(list.get(key) + " "); } System.out.println(); //遍历用户一 for (Integer key : user1) { System.out.print(list.get(key) + " "); } System.out.println(); //遍历用户二 for (Integer key : user2) { System.out.print(list.get(key) + " "); } System.out.println(); //遍历用户三 for (Integer key : user3) { System.out.print(list.get(key) + " "); }
斗地主游戏,嘻嘻嘻
最新推荐文章于 2024-08-18 21:36:31 发布