Java斗地主

 1 package com.biggw.day14.demo05;
 2 
 3 import java.util.*;
 4 
 5 /**
 6  * @author gw
 7  * @date 2019/11/6 0006 下午 17:20
 8  */
 9 
10 /*
11  * 斗地主
12  * */
13 public class DouDiZhu {
14     public static void main(String[] args) {
15         List<String> color = List.of("♦", "♣", "♠", "♥");
16         List<String> numbers = List.of("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2");
17 
18         // 存储牌的索引
19         ArrayList<Integer> pokerIndex = new ArrayList<>();
20         // 存储牌的索引和组装好的牌
21         HashMap<Integer, String> hashMap = new HashMap<>();
22         int count = 0;
23         hashMap.put(53, "小王");
24         hashMap.put(54, "大王");
25         for (int j = 0; j < numbers.size(); j++) {
26             for (int i = 0; i < color.size(); i++) {
27                 ++count;
28                 pokerIndex.add(count);
29                 hashMap.put(count, color.get(i) + numbers.get(j));
30             }
31         }
32         Collections.addAll(pokerIndex, 53, 54);
33         System.out.println("pokerIndex = " + pokerIndex);
34         System.out.println("hashMap = " + hashMap);
35 
36         // 洗牌
37         Collections.shuffle(pokerIndex);
38 
39         ArrayList<Integer> player1 = new ArrayList<>();
40         ArrayList<Integer> player2 = new ArrayList<>();
41         ArrayList<Integer> player3 = new ArrayList<>();
42         ArrayList<Integer> diPai = new ArrayList<>();
43 
44         ArrayList<String> player1Poker = new ArrayList<>();
45         ArrayList<String> player2Poker = new ArrayList<>();
46         ArrayList<String> player3Poker = new ArrayList<>();
47         ArrayList<String> diPaiPoker = new ArrayList<>();
48 
49         // 发牌
50         for (int i = 0; i < pokerIndex.size(); i++) {
51             Integer index = pokerIndex.get(i);
52             if (i >= 51) {
53                 diPai.add(index);
54             } else if (i % 3 == 0) {
55                 player1.add(index);
56             } else if (i % 3 == 1) {
57                 player2.add(index);
58             } else if (i % 3 == 2) {
59                 player3.add(index);
60             }
61         }
62         Collections.sort(player1);
63         Collections.sort(player2);
64         Collections.sort(player3);
65         Collections.sort(diPai);
66 
67 
68         Set<Integer> integers = hashMap.keySet();
69         Iterator<Integer> iterator = integers.iterator();
70         for (int i = 0; i < player1.size(); i++) {
71             player1Poker.add(hashMap.get(player1.get(i)));
72         }
73         for (int i = 0; i < player2.size(); i++) {
74             player2Poker.add(hashMap.get(player2.get(i)));
75         }
76         for (int i = 0; i < player3.size(); i++) {
77             player3Poker.add(hashMap.get(player3.get(i)));
78         }
79         for (int i = 0; i < diPai.size(); i++) {
80             diPaiPoker.add(hashMap.get(diPai.get(i)));
81         }
82 
83 
84         System.out.println("player1Poker = " + player1Poker);
85         System.out.println("player2Poker = " + player2Poker);
86         System.out.println("player3Poker = " + player3Poker);
87         System.out.println("diPaiPoker = " + diPaiPoker);
88     }
89 
90 }



pokerIndex = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54]
hashMap = {1=♦3, 2=♣3, 3=♠3, 4=♥3, 5=♦4, 6=♣4, 7=♠4, 8=♥4, 9=♦5, 10=♣5, 11=♠5, 12=♥5, 13=♦6, 14=♣6, 15=♠6, 16=♥6, 17=♦7, 18=♣7, 19=♠7, 20=♥7, 21=♦8, 22=♣8, 23=♠8, 24=♥8, 25=♦9, 26=♣9, 27=♠9, 28=♥9, 29=♦10, 30=♣10, 31=♠10, 32=♥10, 33=♦J, 34=♣J, 35=♠J, 36=♥J, 37=♦Q, 38=♣Q, 39=♠Q, 40=♥Q, 41=♦K, 42=♣K, 43=♠K, 44=♥K, 45=♦A, 46=♣A, 47=♠A, 48=♥A, 49=♦2, 50=♣2, 51=♠2, 52=♥2, 53=小王, 54=大王}
player1Poker = [♦3, ♦5, ♣5, ♥5, ♣6, ♠6, ♣7, ♠7, ♠8, ♥9, ♥10, ♥J, ♥Q, ♠K, ♠A, ♣2, ♠2]
player2Poker = [♣3, ♦4, ♥6, ♥7, ♣8, ♥8, ♦9, ♠9, ♦10, ♣10, ♠10, ♦J, ♣J, ♠J, ♦Q, ♣Q, ♠Q]
player3Poker = [♠3, ♥3, ♣4, ♥4, ♠5, ♦6, ♦7, ♣9, ♦K, ♣K, ♦A, ♣A, ♥A, ♦2, ♥2, 小王, 大王]
diPaiPoker = [♠4, ♦8, ♥K]

猜你喜欢

转载自www.cnblogs.com/biggw/p/11808746.html
今日推荐