java斗地主demo

package com.learn.Demo9;

import java.util.*;

/* 准备牌:

    牌可以设计为一个ArrayList<String>,每个字符串为一张牌。
    每张牌由花色数字两部分组成,我们可以使用花色集合与数字集合嵌套迭代完成每张牌的组装。
    牌由Collections类的shuffle方法进行随机排序。

    * 发牌

    将每个人以及底牌设计为ArrayList<String>,将最后3张牌直接存放于底牌,剩余牌通过对3取模依次发牌。


    * 看牌

    直接打印每个集合。

*/
public class Demo1 {
public static void main(String[] args) {
HashMap<Integer,String> pokerBox=new HashMap<>();
Integer pokerBoxindex=0;
ArrayList pokerBoxindexnumber=new ArrayList<>();
ArrayList colors=new ArrayList<>();
ArrayList numbers=new ArrayList<>();
//1.4 分别给花色 以及 数字集合添加元素
colors.add(“♥”);
colors.add(“♦”);
colors.add(“♠”);
colors.add(“♣”);
for(int i = 2; i<=10 ; i++){
numbers.add(i+"");
}
numbers.add(“J”);
numbers.add(“Q”);
numbers.add(“K”);
numbers.add(“A”);

    System.out.println(colors);
    System.out.println(numbers);
    //1.6大王小王并添加编号
    pokerBox.put(pokerBoxindex,"大☠");
    pokerBoxindexnumber.add(pokerBoxindex);
    ++pokerBoxindex;
    pokerBox.put(pokerBoxindex,"小☺");
    pokerBoxindexnumber.add(pokerBoxindex);

    for(String color:colors){
        for (String number:numbers) {
            ++pokerBoxindex;
            pokerBox.put(pokerBoxindex,color+number);
            pokerBoxindexnumber.add(pokerBoxindex);
            }
        }
    System.out.println(pokerBox);
    System.out.println(pokerBoxindexnumber);

// 洗牌
Collections.shuffle(pokerBoxindexnumber);
System.out.println(pokerBoxindexnumber);
ArrayList A1=new ArrayList<>();
ArrayList B2=new ArrayList<>();
ArrayList C3=new ArrayList<>();
ArrayList dipai=new ArrayList<>();
Iterator iterator=pokerBoxindexnumber.iterator();
int i=0;
while (iterator.hasNext()){
if (i<51){
if (i%30){
A1.add(iterator.next());
}else if(i%3
1){
B2.add(iterator.next());
}else if(i%3==2){
C3.add(iterator.next());
}
}else {
dipai.add(iterator.next());
}
++i;
}

        System.out.println(A1);
        System.out.println(B2);
        System.out.println(C3);
        System.out.println(dipai);
        Collections.shuffle(A1);
        Collections.shuffle(B2);
        Collections.shuffle(C3);
        Collections.shuffle(dipai);
        lookpaker("A1",pokerBox,A1);
        lookpaker("B2",pokerBox,B2);
        lookpaker("C3",pokerBox,C3);
        lookpaker("底牌",pokerBox,dipai);

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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值