关于斗地主类似案例

关于斗地主类似案例,第1张

关于斗地主类似案例
package com.guigu.test.homework19.listandset;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


public class Text1 {
    public static void main(String[] args) {
        //做牌
        String[] flower = {"♥", "♠", "♦", "♣"};
        String[] dian = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] wang = {"JOKER", "joker"};
        ArrayList box = new ArrayList<>();
        for (String s : flower) {
            for (String s1 : dian) {
                box.add(s + s1);
            }
        }
        box.add(wang[0]);
        box.add(wang[1]);
        //洗牌
        Collections.shuffle(box);
        //分牌
        ArrayList Player1 = new ArrayList<>();
        ArrayList Player2 = new ArrayList<>();
        ArrayList Player3 = new ArrayList<>();
        ArrayList Player4 = new ArrayList<>();
        ArrayList Player5 = new ArrayList<>();
        for (int i = 0; i < box.size(); i++) {
            if (i % 4 == 0 && i < 44) {
                Player1.add(box.get(i));
            } else if (i % 4 == 1 && i < 44) {
                Player2.add(box.get(i));
            } else if (i % 4 == 2 && i < 44) {
                Player3.add(box.get(i));
            } else if (i % 4 == 3 && i < 44) {
                Player4.add(box.get(i));
            } else{
                Player5.add(box.get(i));
            }
        }

        //清牌
        //偷梁换柱
        ArrayList list = new ArrayList<>();
        Collections.addAll(list,"3","4","5","6","7","8","9","1","J","Q","K","A","2","o","O");
        Comparator rull = new Comparator(){
            @Override
            public int compare(String o1, String o2) {
                char c = o1.charAt(1);
                char c1 = o2.charAt(1);
                int i = list.indexOf(c + "");
                int i1 = list.indexOf(c1 + "");
                return i-i1;
            }
        };
        Player1.sort(rull);
        Player2.sort(rull);
        Player3.sort(rull);
        Player4.sort(rull);
        Player5.sort(rull);
        System.out.println("Player1 = " + Player1);
        System.out.println("Player2 = " + Player2);
        System.out.println("Player3 = " + Player3);
        System.out.println("Player4 = " + Player4);
        System.out.println("Player5 = " + Player5);
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5438112.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存