模拟斗地主发牌

import java.util.ArrayList;

import java.util.Collections;

public class GameTest {

public static void main(String[] args) {

//买牌,即创建牌

String [] arr = {"黑桃","红桃","方片","梅花"};

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

//创建集合对象,存储

ArrayList box = new ArrayList();

//遍历数组,进行添加

for (int i = 0; i < arr.length; i++) {

//获取每一个花色

for (int j = 0; j < arr2.length; j++) {

//获取每一个数

//添加进牌的集合

box.add(arr[i]+arr2[j]);

}

}

box.add("大王");

box.add("小王");

//洗牌

Collections.shuffle(box);

System.out.println(box);

//发牌给三个人

//创建三个集合对象,用于存储各自的牌

ArrayList 刘备 = new ArrayList();

ArrayList 关羽 = new ArrayList();

ArrayList 张飞 = new ArrayList();

/*

* 一共54张牌,除去底牌51张牌,分别发给三个人,

* 0%3=0

* 1%3=1

* 2%3=2

* 3%3=0

* 4%3=1

* 5%3=2

* 6%3=0

* .

* .

* .

* 49%3=1

* 50%3=2

* 51%=0

*/

for(int i =0;i

if(i%3==0){

刘备.add(box.get(i));

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

关羽.add(box.get(i));

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

张飞.add(box.get(i));

}

}

System.out.println("刘备:"+刘备);

System.out.println("关羽:"+关羽);

System.out.println("张飞:"+张飞);

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

for(int i = box.size()-3;i

System.out.println(box.get(i));

}

}

}

你可能感兴趣的:(模拟斗地主发牌)