其他分享
首页 > 其他分享> > 斗地主

斗地主

作者:互联网

public class DouDiZhu {
public static void main(String[] args) {
//1.准备牌
//定义一个存储54张牌的集合ArrayList,泛型使用字符串
ArrayList poker=new ArrayList<>();
//定义两个集合分别存储花色和序号
String[] colors={“♠”,“♥”,“♦”,“♣”};
String[] numbers={“2”,“A”,“K”,“Q”,“J”,“10”,“9”,“8”,“7”,“6”,“5”,“4”,“3”};
//将大王小王添加到集合里
poker.add(“大王”);
poker.add(“小王”);
//循环嵌套遍历两个数组,组装53张牌
//使用增强for循环
for(String number:numbers){
for (String color : colors) {
// System.out.println(color+number);
poker.add(color+number);
}
}
System.out.println(poker);
//2.洗牌
//使用集合的工具类collections中的方法
Collections.shuffle(poker);
//3.发牌
//定义4个集合存储玩家牌和底牌
ArrayList player01=new ArrayList<>();
ArrayList player02=new ArrayList<>();
ArrayList player03=new ArrayList<>();
ArrayList diPai=new ArrayList<>();
for(int i=0;i<poker.size();i++){
String p=poker.get(i);
if(i>=51){
diPai.add§;}
else if(i%30){
player01.add§;
}else if(i%3
1){
player02.add§;
}else if(i%3==2){
player03.add§;
}
}
//4.排序
Collection.sort(player01);
Collection.sort(player02);
Collection.sort(player03);
Collection.sort(diPai);
//5.看牌
System.out.print(“张三的牌”+player01);
System.out.println();
System.out.print(“李四的牌”+player02);
System.out.println(http://yezishuju.com/);
System.out.print(“王五的牌”+player03);
System.out.println();
System.out.print(“底牌”+diPai);

}

}

标签:poker,String,斗地主,ArrayList,System,add,out
来源: https://blog.csdn.net/yezikeji/article/details/113766184