package com.niit.cs;
import java.util.Random;
public class TestPoker {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random rand=new Random();
TestPoker tp=new TestPoker();
//定义大小为54的数组
int poker[]=new int[54];
//对数组赋值
for(int i=0;i<poker.length;i++){
poker[i]=i+1;
}
//洗牌
for(int i=1;i<poker.length;i++){
tp.swap(poker,rand.nextInt(54),rand.nextInt(54));
}
//发牌
for(int i=0;i<poker.length;i++){
System.out.print(tp.getColor(poker[i])+""+tp.getPoint(poker[i])+"\t");
if((i+1) % 17==0){
System.out.println();
}
}
}
//获取扑克的点数
public String getPoint(int pokerNum){
String result="";
if(pokerNum==53){
result="小王";
}
else if(pokerNum==54){
result="大王";
}
else{
//这里是求余数
switch(pokerNum%13){
case 0:
result="K";
break;
case 12:
result="Q";
break;
case 11:
result="J";
break;
default:
result = pokerNum % 13+"";
break;
}
}
return result;
}
public String getColor(int pokerNum){
String color="";
if(pokerNum==53){
color="黑白";
}
else if(pokerNum==54){
color="彩色";
}
else{
//这里是整除所以结果就是 0到3之间的数
switch((pokerNum-1)/13){
case 0:
color="红桃";
break;
case 1:
color="黑桃";
break;
case 2:
color="棉花";
break;
case 3:
color="方块";
break;
}
}
return color;
}
//洗牌的方法(下标0~53)
public void swap(int poker[],int i,int j){
int temp =poker[i];
poker[i] = poker[j];
poker[j] = temp;
}
}
java 洗牌
最新推荐文章于 2023-09-12 21:47:21 发布