斗地主比大小 java_Java模拟斗地主(实现大小排序)

importjava.util.Arrays;importjava.util.Collections;importjava.util.HashMap;importjava.util.List;importjava.util.Map;public classDouDiZhu {public static Integer[] index = new Integer[54];private static Map allCard = new HashMap();public static voidmain(String[] args) {

initMap(allCard);//1.) 初始化卡牌

List list =Arrays.asList(initIndex(index));

Collections.shuffle(list);//2.)洗牌//3.)发牌

List player1 = list.subList(0, 17);

List player2 = list.subList(17, 34);

List player3 = list.subList(34, 51);

List dipai = list.subList(51, 54);//4.)按大小排序

Collections.sort(player1);

Collections.sort(player2);

Collections.sort(player3);

Collections.sort(dipai);

System.out.print("玩家1:");for(Integer i :player1){

System.out.print(allCard.get(i));

}

System.out.println();

System.out.print("玩家2:");for(Integer i :player2){

System.out.print(allCard.get(i));

}

System.out.println();

System.out.print("玩家3:");for(Integer i :player3){

System.out.print(allCard.get(i));

}

System.out.println();

System.out.print("底牌 :");for(Integer i :dipai){

System.out.print(allCard.get(i));

}

}//初始化卡牌数量

public staticInteger[] initIndex(Integer[] index) {for (int i = 1; i < 55; i++) {

index[i- 1] =i;

}returnindex;

}//将卡牌按大小以及花色(黑红梅方)添加到map

public static void initMap(Mapmap) {

String[] num= { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6","5", "4", "3"};

String[] color= { "♠","♥","♦","♣"};

map.put(1, "|BK|");

map.put(2, "|SK|");int k = 3;for (int i = 0; i < num.length; i++) {for (int j = 0; j < color.length; j++) {

map.put(k, color[j]+num[i]);

k++;

}

}

}

}

运行结果:

f56ba3023c93eafde4bcdbfeb033cd64.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值