当前位置 : 主页 > 编程语言 > c++ >

@author Believer

来源:互联网 收集:自由互联 发布时间:2021-06-30
模拟斗地主洗牌发牌功能 package test;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;/** * * 模拟斗地主功能 * @author Believer * */public class DouDiZhu {public static void main(String[] arg
模拟斗地主洗牌发牌功能
package test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/**
 * 
 * 模拟斗地主功能
 * @author Believer
 *
 */
public class DouDiZhu {
	public static void main(String[] args) {
		//创建Map集合,Key-->编号,Value-->牌
		HashMap
 
   pooker = new HashMap
  
   (); //创建List集合,存储编号 ArrayList
   
     pookerNumber = new ArrayList
    
     (); //定义13个点色数组 String numbers[] = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"}; //定义4个花色数组 String colors[] = {"♥","♠","♣","♦"}; int index = 2; //遍历数组,花色+点数组合存储到Map集合 for(String number : numbers){ for(String color : colors){ pooker.put(index, color+number); pookerNumber.add(index); index++; } } //存储大小王 pooker.put(0, "大王"); pookerNumber.add(0); pooker.put(1, "小王"); pookerNumber.add(1); //洗牌,将牌的编号打乱 Collections.shuffle(pookerNumber); //创建玩家和底牌 ArrayList
     
       player1 = new ArrayList
      
       (); ArrayList
       
         player2 = new ArrayList
        
         (); ArrayList
         
           player3 = new ArrayList
          
           (); ArrayList
           
             bottom = new ArrayList
            
             (); for(int i = 0;i
             
               list,HashMap
              
                pooker){ for(Integer key : list){ String value = pooker.get(key); System.out.print(value+"\t"); } System.out.println(); } }
              
             
            
           
          
         
        
       
      
     
    
   
  
 
网友评论