用户注册



邮箱:

密码:

用户登录


邮箱:

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

发表随想


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

打地主三个人的牌

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

[java]代码库

public class Example_01 {
	int[]  total=new int[54];
	int player1[]=new int[17];
	int player2[]=new int[17];
	int player3[]=new int[20];
String Colors[]=new String[]{"黑桃","红桃","方块","梅花"};
	private String getColors(int number){
		int index=number%4;
		return Colors[index];
	} 
	String mostPokers[]=new String[]{"2","3","4","5","6","7","8","9","10","J","Q","K","A","大王","小王"};
	private String getsNumber(int pokersNumber){
		if(pokersNumber<52){
			int onePokers=pokersNumber/4;
			return getColors(pokersNumber)+mostPokers[onePokers];
		}else if(pokersNumber==52){
			return mostPokers[mostPokers.length-2];
		}else if(pokersNumber==53){
			return mostPokers[mostPokers.length-1];
		}
		return null;
	}
	public void playGame(){
		for(int i=0;i<total.length;i++){
			total[i]=-1;
		}
		for(;;){
			int number=(int)(Math.random()*54);
			for(int j=0;j<total.length;j++){
				int number2=total[j];
				if(number==number2){
					break;
				}
				if(number2==-1){
					total[j]=number;
					break;
				}
			}
			if(total[total.length-1]!=-1){
				break;
			}
		}
		sumPokers(total);
	}
	private void sumPokers(int[] total2) {
	int number3=(int)(Math.random()*52);
	System.out.println("地主牌为:"+getsNumber(total2[number3]));
	int diZhu=number3%3;
	int player1[]=new int[17];
	int player2[]=new int[17];
	int player3[]=new int[17];
	for(int i=0;i<total2.length;i++){
		if(i<total2.length-3){
			int players=i%3;
			int peoplePokers=i%17;
			if(players==0){
				player1[peoplePokers]=total2[i];
			}else if(players==1){
				player2[peoplePokers]=total2[i];
			}else{
				player3[peoplePokers]=total2[i];
				}
			}else{
				if(diZhu==0){
					int diZhuPokers[]=new int[20];
				for(int j=0;j<player1.length;j++){
					diZhuPokers[j]=player1[j];
				}
				for(int k=17;k<20;k++){
					diZhuPokers[k]=total2[k+34];
					}
				player1=diZhuPokers;
				System.out.println("\n\n玩家1为地主:");
				}else if(diZhu==1){
					int diZhuPokers[]=new int[20];
					for(int j=0;j<player2.length;j++){
						diZhuPokers[j]=player2[j];
					}
					for(int k=17;k<20;k++){
						diZhuPokers[k]=total2[k+34];
					}
					player2=diZhuPokers;
				System.out.println("\n\n玩家2为地主:");
				}else{
					int diZhuPokers[]=new int[20];
					for(int j=0;j<player3.length;j++){
						diZhuPokers[j]=player3[j];
					}
					for(int k=17;k<20;k++){
						diZhuPokers[k]=total2[k+34];
					}
					player3=diZhuPokers;
				System.out.println("\n\n玩家3为地主:");
				}
				player1=paiXu(player1);
				player2=paiXu(player2);
				player3=paiXu(player3);
				System.out.println("地主是:"+(player1.length==20?"玩家1为地主":player2.length==20?"玩家2为地主":player3.length==20?"玩家3为地主":""));
				System.out.println("玩家1的牌为:");
				for(int player1Num=0;player1Num<player1.length;player1Num++){
					System.out.print(" "+getsNumber(player1[player1Num]));
				}
				System.out.println("\n\n玩家2的牌为:");
				for(int player2Num=0;player2Num<player2.length;player2Num++){
					System.out.print(" "+getsNumber(player2[player2Num]));
				}
				System.out.println("\n\n玩家3的牌为:");
				for(int player3Num=0;player3Num<player3.length;player3Num++){
					System.out.print(" "+getsNumber(player3[player3Num]));
				}
				break;
			}
		}
	}
	private int[] paiXu(int[] players) {
		int nullNumber=-1;
		for(int i=0;i<players.length;i++){
			for(int j=0;j<players.length;j++){
				if(players[i]<players[j]){
					nullNumber=players[i];
					players[i]=players[j];
					players[j]=nullNumber;
				}
			}
		}
		return players;
	}
}






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


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

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


扫码下载

加载中,请稍后...

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

加载中,请稍后...