在命令行运行有效果.eclipse上是乱码... 另外问下..大家在论坛上发的那种格式怎么发.. 就是左边带行数的,最下面能复制全篇的那种..
路过的大神多提宝贵意见哈~
/*
需求: 数组自我练习,利用数组创建一副扑克牌 实现斗地主简单发牌功能
思路:1,创建54大小的数组
2,令创建4个存放牌的数组.
3,利用循环及switch实现发牌功能
*/
public class test {
private String[] pock=new String[54];
private String[] player1=new String[17];
private String[] player2=new String[17];
private String[] player3=new String[17];
private String[] temp=new String[3];
private int pocktemp[]=new int[54];
private char[] a=new char[]{3,4,5,6};
private String j="大王",bj="小王";
public test()
{
setpock();
}
private void setpock()
{
int hos=0;
for(int x=0;x<50;x=x+13)
{
for(int i=0;i<13;i++)
pock[i+x]=a[hos]+""+(i+1);
hos++;
}
hos=0;
for(int i=0;i<40;i=i+13)
{
pock=a[hos]+"A";
hos++;
}
hos=0;
for(int i=10;i<50;i=i+13)
{
pock=a[hos]+"J";
hos++;
}
hos=0;
for(int i=11;i<51;i=i+13)
{
pock=a[hos]+"Q";
hos++;
}
hos=0;
for(int i=12;i<52;i=i+13)
{
pock=a[hos]+"K";
hos++;
}
pock[52]=bj;
pock[53]=j;
}
private void setplayer()
{
int pdindex=0,tempindex=0,p1index=0,p2index=0,p3index=0,flag=0;
int pockcase = 0;
boolean flag2=false;
for(int i=0;i<54;i++)
{
for(;;){
flag2=true;
pockcase=(int)(Math.random()*54);
if(!(pdindex==0))
for(int j=0;j<pdindex;j++)
{
if((pocktemp[j]==pockcase))
{
flag2=false;
break;
}
};
if(flag2)
{
pocktemp[pdindex]=pockcase;
pdindex++;
break;
}
}
if(i>=51){
temp[tempindex++]=pock[pockcase];
}else
switch (++flag){
case 1:
player1[p1index++]=pock[pockcase];
break;
case 2:
player2[p2index++]=pock[pockcase];
break;
case 3:
player3[p3index++]=pock[pockcase];
flag=0;
break;
}
}
}
public static void main(String[] args)
{
test t=new test();
t.setplayer();
System.out.println("牌库:");
for(String x:t.pock)
System.out.print(x+" ");
System.out.println();
System.out.println("玩家1:");
for(String x:t.player1)
System.out.print(x+" ");
System.out.println();
System.out.println("玩家2:");
for(String x:t.player2)
System.out.print(x+" ");
System.out.println();
System.out.println("玩家3:");
for(String x:t.player3)
System.out.print(x+" ");
System.out.println();
System.out.println("待抢:");
System.out.println();
for(String x:t.temp)
System.out.print(x+" ");
System.out.println("\n发牌结束");
}
}
|
|