模拟斗地主发牌(简易版本)

package com.czie.iot1913.lps.List;

import java.util.ArrayList;
import java.util.Collections;

/**
* @author 1944900433@qq.com
* @date 2022-03-20 23:29
*/
public class LandlordsTest {
public static void main(String[] args) {
//创建一个牌盒
ArrayList<String> array = new ArrayList<String>();
//往牌盒装牌
/*
♦、♣、♥、♠、🃏、🃏
*/
String[] colors={"♦","♣","♥","♠"};
//定义点数数组
String[] numbers={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
for(String color:colors){
for (String number:numbers){
array.add(color+number);
}
}
array.add("小王");
array.add("大王");

Collections.shuffle(array);
//发牌,遍历集合,给三个玩家发牌
ArrayList<String> lpxArrat = new ArrayList<String>();
ArrayList<String> lpsArray = new ArrayList<String>();
ArrayList<String> lpjArray = new ArrayList<String>();
ArrayList<String> dpArray = new ArrayList<String>();
for (int i = 0; i < array.size(); i++) {
String poker = array.get(i);
if (i>= array.size()-3){
dpArray.add(poker);
}else if(i%3==0){
lpsArray.add(poker);
}else if(i%3==1){
lpjArray.add(poker);
}else if(i%3==2) {
lpxArrat.add(poker);
}
}
lookPoker("刘品水:",lpsArray);

lookPoker("刘平静:",lpjArray);

lookPoker("刘品行:",lpxArrat);
lookPoker("底牌",dpArray);


}
public static void lookPoker(String name,ArrayList<String> array){
System.out.println(name+"的牌是:");
for (String poker:array){
System.out.print(poker+" ");
}
System.out.println();
}
}

 

posted @ 2022-03-21 21:58  刘品水  阅读(125)  评论(0编辑  收藏  举报