简单的学习了java语法后写的一斗地主发牌算法练练手
idea测试通过
欢迎参考
import java.util.Random;
public class Fapai {
static class poker{
public String color;
public String dian;
public poker(String i,String j){
this.color=i;
this.dian=j;
}
public void printf(poker i){
System.out.print(i.color+i.dian+" ");
}
}
static class Delete{
public void delete(poker[] p,int i){
for(int j=i;j<p.length-1;j++) {
p[j] = p[j + 1];
}
}
}
static public void cunpai(){
String[] Huase = {"黑桃", "梅花", "红桃", "方块"};
String[] Dian = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "大王", "小王"};
poker[][] p = new poker[5][13];
poker[] P=new poker[54];
p[4][1]=new poker("大","王");
p[4][2]=new poker("小","王");
Delete D=new Delete();
P[52]=p[4][1];
P[53]=p[4][2];
//存入卡片
for (int i = 0,k=0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
p[i][j]=new poker(Huase[i],Dian[j]);
P[k]=p[i][j];
//D.delete(P,51);
P[k].printf(P[k]);
k++;
}
System.out.println();
}
P[52].printf(P[52]);
P[53].printf(P[53]);
System.out.println();
Random n=new Random();
int player=1;
int all=54;
for (int i=0;i<54;i++){
if(i%17==0)
{
if(player==4)
{
player=0;
System.out.println("\n\n");
System.out.println("地主牌:");
}
System.out.println();
System.out.println("玩家"+player+":");
player++;
}
int x=n.nextInt(all);
P[x].printf(P[x]);
D.delete(P,x);
all--;
}
}
public static void main (String[] args) {
cunpai();
System.out.println("*********测试分割线*********");
}
}