- //思路:(买牌,做牌),洗牌, 发牌, 看底牌, 看玩家牌
- public static void main(String[] args) {
- //定义三个玩家
- ArrayList<String> liudehua = new ArrayList<String>();
- ArrayList<String> linqingxia = new ArrayList<String>();
- ArrayList<String> ziji = new ArrayList<String>();
- //定义一个牌盒
- ArrayList<String > pai = new ArrayList<>();
- //做牌
- String[] stg1 = {"黑桃","红桃","梅花","方块"};
- String[] stg2 = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
- for(String s1 : stg1 ){
- for(String s2 : stg2){
- pai.add(s1.concat(s2));
- }
- }
-
- pai.add("大王");
- pai.add("小王");
- //洗牌
- Collections.shuffle(pai);
- //发牌
- for(int x = 0 ; x < pai.size() -3; x++){//取余定位玩家发牌
- if(x%3==0){
- liudehua.add(pai.get(x));
- }else if (x%3==1){
- linqingxia.add(pai.get(x));
- }else if (x%3==2) {
- ziji.add(pai.get(x));
- }
- }
-
- System.out.println("liudehua"+liudehua);//查看玩家手牌
- System.out.println("linqingxia"+linqingxia);
- System.out.println("jixi"+ziji);
- //看底牌
- System.out.println("底牌是:");
- for(int x = pai.size()-3 ; x<pai.size(); x++){
- System.out.print(""+pai.get(x)+" ");
- }
- }
复制代码 |