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(); |
} |
} |
by: 发表于:2017-07-14 10:10:30 顶(0) | 踩(0) 回复
??
回复评论