package it.SetDemo03;
import java.util.ArrayList;
import java.util.Collections;
/**
* 需求:编写一个小程序 ,目的是斗地主;
* A:买牌
* B:洗牌
* C:发牌
* D:看底牌
*
*/
public class PuKePai {
public static void main(String[] args) {
String[] s1={"黑桃","红桃","梅花","方块"};
String[] s2={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
//买牌
ArrayList<String> array=new ArrayList<String>();
array.add("大王");
array.add("小王");
for (int i = 0; i < s1.length; i++) {
for (int j = 0; j < s2.length; j++) {
array.add(s1[i].concat(s2[j]));
}
}
//System.out.println(array);
for (int j = 0; j < 3; j++) {
Collections.shuffle(array);
}
//发牌
//普通for循环
ArrayList<String> wanjia1=new ArrayList<String>();
ArrayList<String> wanjia2=new ArrayList<String>();
ArrayList<String> wanjia3=new ArrayList<String>();
for (int x = 0; x < array.size()-3; x++) {
if(x%3==0){
wanjia1.add(array.get(x));
}
else if(x%3==1){
wanjia2.add(array.get(x));
}
else if(x%3==2){
wanjia3.add(array.get(x));
}
}
//看底盘
for (int y = array.size()-3; y < array.size(); y++) {
System.out.print(array.get(y)+"\t");
}
System.out.println();
System.out.print("玩家1的牌: ");
System.out.println(wanjia1);
System.out.print("玩家2的牌: ");
System.out.println(wanjia2);
System.out.print("玩家3的牌: ");
System.out.println(wanjia3);
}
}
|
|