斗地主(排序)

斗地主案例

/*
* 1,准备牌
* 2.发牌
* 3.排序
* 4.看牌*/

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

public class DouDiZhu {
    public static void main(String[] args) {
        //1.准备牌
        HashMap<Integer,String> poker = new HashMap<>();
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        String[] color = {"♠","♥","♣","♦"};
        String[] numbers = {"2","A","K","J","Q","10","9","8","7","6","5","4","3"};
        int index = 0;
        poker.put(index,"大王");
        pokerIndex.add(index);
        index++;
        poker.put(index,"小王");
        pokerIndex.add(index);
        index++;
        for (String s : color) {
            for (String number : numbers) {
                poker.put(index,s+number);
                pokerIndex.add(index);
                index++;

            }
        }
        System.out.println("看牌:");
        System.out.println(poker);
        Collections.shuffle(pokerIndex);
        //发牌
        ArrayList<Integer> one = new ArrayList<>();
        ArrayList<Integer> two = new ArrayList<>();
        ArrayList<Integer> three = new ArrayList<>();
        ArrayList<Integer> diapi = new ArrayList<>();
        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer in = pokerIndex.get(i);
            if(i >= 51){
                diapi.add(in);
            }else if (i % 3 == 0){
                one.add(in);
            }else if (i % 3 == 1) {
                two.add(in);
            }else if (i % 3 == 2) {
                three.add(in);
            }

        }
        Collections.sort(one);
        Collections.sort(two);
        Collections.sort(three);
        Collections.sort(diapi);

        //看牌
        lookpoker("孙佳明",poker,one);
        lookpoker("王天昊",poker,two);
        lookpoker("董耘伯",poker,three);
        lookpoker("底牌",poker,diapi);


    }

    private static void lookpoker(String name , HashMap<Integer,String> poker, ArrayList<Integer> pokerIndex) {
        System.out.print(name + ":   ");
        for (Integer key : pokerIndex) {
            String value = poker.get(key);
            System.out.print(value + " ");
        }
        System.out.println();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值