【Java】斗地主综合案例

斗地主综合案例2


 

public class DouDiZhu {

public static void main(String[] args) {

//1.准备牌

//创建一个Map集合,存储牌的索引和组装好的牌

Map<Integer,String> poker = new HashMap<>();

//创建一个List集合,存储牌的索引

List<Integer> pokerIndex = new ArrayList<>();

//定义两个集合,存储花色和牌的序号

List<String> colors = List.of("♥","♠","♦","♣");

List<String> numbers = List.of("2","3","4","5","6","7","8","9","10","J","Q","K","A");

int index = 0;

poker.put(index,"大王");

pokerIndex.add(index);

index++;

poker.put(index,"小王");

pokerIndex.add(index);

index++;

for (String number : numbers){

for(String color : colors){

//String temp = ""+color+number;

poker.put(index,color+number);

pokerIndex.add(index);

index++;

}

}

System.out.println(poker);

System.out.println(pokerIndex);

System.out.println("===================");

//2.洗牌

Collections.shuffle(pokerIndex);

//3.发牌

List<Integer> player01 = new ArrayList<>();

List<Integer> player02 = new ArrayList<>();

List<Integer> player03 = new ArrayList<>();

List<Integer> dipai = new ArrayList<>();

//4.排序 使用Collections.sort

int flag = 0;

for(int i : pokerIndex){

if(flag>50){

dipai.add(i);

}

else if(flag%3==0){

player01.add(i);

}else if(flag%3==1){

player02.add(i);

}else if(flag%3==2){

player03.add(i);

}

flag++;

}

//对玩家手里的牌进行排序

Collections.sort(player01);

Collections.sort(player02);

Collections.sort(player03);

Collections.sort(dipai);

System.out.print("player01:");

for(int i : player01){

System.out.print(poker.get(i)+" ");

}

System.out.println();

System.out.print("player02:");

for(int i : player02){

System.out.print(poker.get(i)+" ");

}

System.out.println();

System.out.print("player03:");

for(int i : player03){

System.out.print(poker.get(i)+" ");

}

System.out.println();

System.out.print("底牌:");

for(int i : dipai){

System.out.print(poker.get(i)+" ");

}


}

}

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值