本帖最后由 jx5785749 于 2015-7-13 23:00 编辑
package cn.itcast.doudizhu;
import java.util.ArrayList;
import java.util.Collections;
public class DouDiZhuTest {
public static void main(String[] args) {
//买排
String [] colors = {"♠","♣","♥","♦"};//花色
String [] counts = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};//点数
ArrayList<String> as = new ArrayList<String>();
for (int i = 0; i < colors.length; i++) {
for (int j = 0; j < counts.length; j++) {
as.add(colors.concat(counts[j]));
}
}
as.add("大王");
as.add("小王");
//洗牌
Collections.shuffle(as);
System.out.println(as);
//发牌
ArrayList<String> liudehua = new ArrayList<String>();
ArrayList<String> zhourunfa = new ArrayList<String>();
ArrayList<String> woziji = new ArrayList<String>();
for ( int x = 0; x < as.size()-3; x++) {
if(x%3==0){
liudehua.add(as.get(x));
}else if(x%3==1){
zhourunfa.add(as.get(x));
}else if(x%3==2){
woziji.add(as.get(x));
}
}
System.out.println("刘德华:"+liudehua);
System.out.println("周润发: "+zhourunfa);
System.out.println("我: "+woziji);
System.out.print("底牌:");
for (int i = as.size()-3; i < as.size(); i++) {
System.out.print(as.get(i)+" ");
}
}
}
|
|