32.斗地主案例

组合牌,洗牌,发牌,看牌
···
package com.ryan01;

import java.util.*;

/**

  • Created by Administrator on 2018/4/30.
    */
    public class Zuhepai {
    public static void main(String[] args){
    HashMap pooker=new HashMap(); //首先给一副牌存个键值对,每一张牌都会有个序号,我们所有的操作都是在对序号进行排序
    HashMap A=new HashMap();
    HashMap B=new HashMap();
    HashMap C=new HashMap();
    HashMap D=new HashMap();
    ArrayList A_key=new ArrayList();
    ArrayList B_key=new ArrayList();
    ArrayList C_key=new ArrayList();
    ArrayList D_key=new ArrayList();
    ArrayList numList=new ArrayList();
    String[] pookerNum={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
    String[] pookerFlower={"♥","♠","♣","♦"};
    int index=2;
    for (String i:pookerNum
    ) {
    for (String j:pookerFlower
    ) {pooker.put(index,j+i);
    numList.add(index);
    index++; }; //给每个牌赋予序号与牌的值
    }
    pooker.put(0,"大王");
    pooker.put(1,"小王");
    numList.add(0);
    numList.add(1);
    Collections.shuffle(numList);
    for(int j=0;j<51;j=j+3){
    A_key.add(numList.get(j));
    }
    for(int j=1;j<51;j=j+3){
    B_key.add(numList.get(j));
    }
    for(int j=2;j<51;j=j+3){
    C_key.add(numList.get(j));
    }
    for(int j=51;j<54;j++){
    D_key.add(numList.get(j));
    }
    Collections.sort(A_key); //给手上的牌排个序
    Collections.sort(B_key);
    Collections.sort(C_key);
    Collections.sort(D_key);
    Set value=pooker.keySet();
    for(int i=0;i<17;i++){
    A.put(A_key.get(i),pooker.get(A_key.get(i)));
    }
    System.out.println(A);
    for(int i=0;i<17;i++){
    B.put(B_key.get(i),pooker.get(B_key.get(i)));
    }
    System.out.println(B);
    for(int i=0;i<17;i++){
    C.put(C_key.get(i),pooker.get(C_key.get(i)));
    }
    System.out.println(C);
    for(int j=0;j<3;j++){
    D.put(D_key.get(j),pooker.get(D_key.get(j)));
    }
    System.out.println(D);
    }
    }

你可能感兴趣的:(32.斗地主案例)