用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

集合形式打印三个人的牌型

2016-12-13 作者: java程序设计举报

[java]代码库

package com.playGame;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Pokers {
	List<Integer> gameCards=new ArrayList<>();
		int card=-1;
	public void playGame(){
		boolean start=true;
		while(start){
			int card=(int)(Math.random()*54);
			if(gameCards.contains(card)){
				continue;
			}
			gameCards.add(card);
			if(gameCards.size()==54){
				break;
			}
		}
		shuffle();
	}
	Map<Integer,ArrayList<Integer>> playsPokers=new HashMap<Integer,ArrayList<Integer>>();
	private void shuffle() {
		int cardsIndex=(int)(Math.random()*52);
		System.out.println("地主牌是:"+getNumber(gameCards.get(cardsIndex)));
		int  landlord=cardsIndex%3;
		playsPokers.put(0,new ArrayList<Integer>());
		playsPokers.put(1,new ArrayList<Integer>());
		playsPokers.put(2,new ArrayList<Integer>());
		for(int i=0;i<gameCards.size();i++){
			int eachPlay=i%3;
			if(i>51){
				playsPokers.get(landlord).add(gameCards.get(i));
			}else{
				playsPokers.get(eachPlay).add(gameCards.get(i));
			}
		}
		showCards();
	}
	private void showCards() {
		for(int i=0;i<3;i++){
			System.out.println("\n玩家"+(i+1));
			List<Integer> everyPokers=playsPokers.get(i);
			for(Integer numberPokers:everyPokers){
				System.out.print("   "+getNumber(numberPokers));
			}
		}
	}
	String [] colors=new String[]{"黑桃","红桃","方块","梅花"};
	public String getColors(int kinds){
		int index=kinds%4;
		return colors[index];
	}
	String [] numbers=new String[]{"2","3","4","5","6","7","8","9","10","J","Q","K","A","小王","大王"};
		public String getNumber(int numberIndex){
			if(numberIndex<52){
				int peopleCards=numberIndex/4;
				return getColors(numberIndex)+numbers[peopleCards];
			}else if(numberIndex==52){
				return numbers[numbers.length-2];
			}else if(numberIndex==53){
				return numbers[numbers.length-1];
			}
			return null;
		}
	}


















package com.playGame;

public class Main {
	public static void main(String args[]){
		Pokers stats=new Pokers();
		stats.playGame();
	}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...