package com.d313;
/*@author DDC
* @date 2020-3-13 22:00
* */
import java.util.Arrays;
import java.util.Random;
public class PokerDemo {
public static void main(String[] args) {
//Poker p=new Poker(3,6);
//System.out.println(p);
/*重写Object类中toString()方法后,打印方片7
p只是一个对象的地址值,所在的类都是默认继承Object类
System.out.println(p);默认情况下,调用的是toString()方法,打印com.d313.Poker@4554617c*/
Poker[] cs=new Poker[54];
int i=0; //赋有序新牌,黑红梅方A,2,3..K
for(int n=0;n<=12;n++){
cs[i++]=new Poker(0,n);
cs[i++]=new Poker(1,n);
cs[i++]=new Poker(2,n);
cs[i++]=new Poker(3,n);
}
cs[i++]=new Poker(4,13);
cs[i++]=new Poker(4,14);//完整有序新牌,黑红梅方A,2,3..K,小,大王
Poker[] cs2=Poker.shuffle(cs); //洗牌
//System.out.println(Arrays.toString(cs2));
Users[] uu=new Users[4];
uu[0]=new Users(101,"Rose");
uu[1]=new Users(102,"Lucy");
uu[2]=new Users(103,"Jack");
uu[3]=new Users(666,"底牌");
for(int k=0;k<cs2.length-3;k++){
Poker cs3=cs2[k];
uu[k%3].provide(cs3);
}
Poker csa=cs2[cs.length-3];
Poker csb=cs2[cs.length-2];
Poker csc=cs2[cs.length-1];
uu[3].provide(csa);
uu[3].provide(csb);
uu[3].provide(csc);
System.out.println(uu[0]);
System.out.println(uu[1]);
System.out.println(uu[2]);
System.out.println(uu[3]);
}
}
class Poker{
int type;
int num;
final String[] TYPE_NAME={"♠","♥","♣","♦",""};
final String[] NUM_NAME={"A","2","3","4","5","6","7","8","9","10","J","Q","K","小王","大王"};
public Poker(int type,int num){
this.type=type;
this.num=num;
}
public static Poker[] shuffle(Poker[] cs){ //洗牌
Random rd=new Random();
for(int i=0;i<cs.length;i++){
int j=rd.nextInt(54);
Poker t=cs[j];
cs[j]=cs[i];
cs[i]=t;
}
return cs;
}
//重写Object类中toString方法
public String toString(){
return TYPE_NAME[type]+NUM_NAME[num];
}
}
class Users{
int id;
String name;
Poker[] cs={};
public Users(int id,String name){
this.id=id;
this.name=name;
}
public void provide(Poker c){ //一张一张轮流发牌到手
cs=Arrays.copyOf(cs,cs.length+1);
cs[cs.length-1]=c;
}
//重写Object类中toString方法
public String toString(){
return id+" "+name+Arrays.toString(cs);
}
}