Java实现斗地主简化版

本文实例为大家分享了Java实现斗地主的具体代码,供大家参考,具体内容如下

package com.westos.chinesePoker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
 *加强版的斗地主 EnhancedVersion
 *在version1.0的基础上加入扑克排序.
 * @author 虎虎
 * @version 2.0
 */
public class ChinesePokerEnhanced {

  public static void main(String[] args) {
    //0-53代表每个对应的扑克
    Map map = new HashMap();
    List list = new ArrayList<>();
    String[] color = {"♥","♠","♣","◆"};
    String[] num = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
    for(String str:num) {
      for(String str1:color) {
        String poker = str1.concat(str);
        list.add(poker);
      }
    }
    list.add("♀");
    list.add("♂");
    for(int i=0;i<54;i++) {
        map.put(i, list.get(i));
      }
    Set keyset = map.keySet();
    List list1 = new ArrayList<>();
    for(Integer count:keyset){
      list1.add(count);
      }
    //洗牌三次
    Collections.shuffle(list1);
    Collections.shuffle(list1);
    Collections.shuffle(list1);

    Set player01 = new TreeSet<>();
    Set player02 = new TreeSet<>();
    Set player03 = new TreeSet<>();
    Set dipai = new TreeSet<>();
    //发牌
    for(int i=0;i=51)
        dipai.add(list1.get(i));


    }
    //玩家一的牌
    System.out.println("玩家一:");
    for(Integer i:player01) {
      System.out.print(map.get(i)+" ");
    }
    System.out.println("\n玩家二:");
    //玩家二的牌
    for(Integer i:player02) {
      System.out.print(map.get(i)+ " ");
    }

    System.out.println("\n玩家三:");
    //玩家三的牌
    for(Integer i:player03) {
      System.out.print(map.get(i)+ " ");
    }
    System.out.println("\n底牌:");
    //玩家一的牌
    for(Integer i:dipai) {
      System.out.print(map.get(i)+ " ");
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Java实现斗地主简化版)