首页 > 代码库 > java之实例斗地主(集合)
java之实例斗地主(集合)
public class CollectionTest {
/**
* 玩斗地主的三个步骤:
* A 买牌
* B 洗牌
* C 发牌
* D 看底牌
*/
public static void main(String[] args) {
String[] color={"黑桃","红桃","梅花","方块"};
String[] numbers={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList<String> array=new ArrayList<String>();
array.add("大王");
array.add("小王");
for (String c : color) {
for (String n : numbers) {
array.add(c.concat(n));
}
}
Collections.shuffle(array);
//System.out.println(array);
//System.out.println(array.size());
//三个人
ArrayList<String> xiaoming1=new ArrayList<String>();
ArrayList<String> xiaoming2=new ArrayList<String>();
ArrayList<String> xiaoming3=new ArrayList<String>();
for (int i = 0; i < array.size()-3; i++) {
if (i%3==0) {
xiaoming1.add(array.get(i));
}else if (i%3==1) {
xiaoming2.add(array.get(i));
}else if (i%3==2) {
xiaoming3.add(array.get(i));
}
}
System.out.println(xiaoming1);
System.out.println(xiaoming2);
System.out.println(xiaoming3);
//看底牌
for (int i = array.size()-3; i < array.size(); i++) {
System.out.print(array.get(i)+" ");
}
}
}