斗地主java编程思想

今天学习的是斗地主,主要用到了列表了for循环的方法。
代码如下:
package com.zhongruan;

import java.util.*;

public class DouDiZhu2 {
public static void main(String[] args) {
//1.拿到一副牌
Map<Integer,String> poker=new HashMap<>();
String[] nums={“A”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“J”,“Q”,“K”};// 创建数组

    String[] colors={"黑桃","红心","梅花","方块"};  //花色的数组
    int index=0;
    for(String color:colors){
        for(String num:nums){
            String pai=color+num;
            index=index+1;
            poker.put(index,pai);
        }
    }
    System.out.println(index);
    index++;
    poker.put(index,"大王");
    index++;
    poker.put(index,"小王");
    System.out.println(poker);
    //2.洗牌
    List<Integer> pokerIndexs=new ArrayList<>();
    Set<Integer> integers = poker.keySet();
  //  System.out.println(integers);
    for(Integer i:poker.keySet()){
        pokerIndexs.add(i);
    }
    Collections.shuffle(pokerIndexs);
    System.out.println(pokerIndexs);
    //3.留3张牌
    Set<Integer> dipaiInds=new TreeSet<>();
    dipaiInds.add(pokerIndexs.remove(0));
    dipaiInds.add(pokerIndexs.remove(0));
    dipaiInds.add(pokerIndexs.remove(0));
    System.out.println(dipaiInds);
    System.out.println(pokerIndexs);
    //4.发牌
    Set<Integer> ct=new TreeSet<>();
    Set<Integer> wwc=new TreeSet<>();
    Set<Integer> sj=new TreeSet<>();
    for(int i=0;i <pokerIndexs.size();i++){
        int pi=pokerIndexs.get(i);
        int mod=i%3;
        if(mod==0){
            ct.add(pi);
        }else if(mod==1){
            wwc.add(pi);
        }else{
            sj.add(pi);
        }
    }
    System.out.println(ct);
    System.out.println(wwc);
    System.out.println(sj);
    //5.看牌
    look(poker,ct);
    look(poker,wwc);
    look(poker,sj);

}

public static void look(Map<Integer,String> poker,Set<Integer> indexs){
    List<String> p=new ArrayList<>();
    for(Integer i:indexs){
        String pai=poker.get(i);
        p.add(pai);
    }
    System.out.println(p);
}

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值