package poker;
public class Card {
protected int color;
protected int number;
public static final int HEART = 0;
public static final int SPADE = 1;
public static final int CLUB = 2;
public static final int DIAMOND = 3;
public static final int BLACK = 4;
public static final int RED = 5;
public static final int THREE = 0;
public static final int FOUR = 1;
public static final int FIVE = 2;
public static final int SIX = 3;
public static final int SEVEN = 4;
public static final int EIGHT = 5;
public static final int NINE = 6;
public static final int TEN = 7;
public static final int JACK = 8;
public static final int QUEEN = 9;
public static final int KING = 10;
public static final int ACE = 11;
public static final int TWO = 12;
public static final int JOKER = 13;
private static final String[] Color={"红桃","黑桃","梅花","方块","小","大"};
private static final String[] Number="3,4,5,6,7,8,9,10,J,Q,K,A,2,王".split(",");
public Card(){
super();
}
public Card(int color, int number) {
super();
if (color >= 0 && color <= 3 && number >= 0 && number < 13) {
this.color = color;
this.number = number;
} else if (number == 13 && (color == 4 || color == 5)) {
this.color = color;
this.number = number;
} else {
System.out.println("error");
}
}
public String GetCard(){
return Color[color]+Number[number];
}
}
package poker;
import java.util.Random;
public class Poker {
private Card[] poker=new Card[54];
public Poker(){
int j=0;
for(int i=Card.THREE;i<=Card.TWO;i++){
this.poker[j++]=new Card(Card.HEART, i);
this.poker[j++]=new Card(Card.SPADE, i);
this.poker[j++]=new Card(Card.CLUB, i);
this.poker[j++]=new Card(Card.DIAMOND, i);
}
this.poker[j++]=new Card(Card.BLACK, Card.JOKER);
this.poker[j]=new Card(Card.RED, Card.JOKER);
}
public Card[] GetPoker(){
return poker;
}
/*
* 洗牌
public void Shuffle(){
boolean[] CardFlag=new boolean[54];
Random CardRandom=new Random();
Card[] tmpPoker=new Card[54];
int CardNum;
for(int i=0;i<54;i++){
tmpPoker[i]=new Card();
do {
CardNum=CardRandom.nextInt(54);
}while(CardFlag[CardNum]);
tmpPoker[i]=poker[CardNum];
CardFlag[CardNum]=true;
}
poker=tmpPoker;
}
*/
/*
* 由最后一张牌开始洗牌
*/
public void Shuffle(){
Card tmpCord=new Card();
Random tmpCardRandom=new Random();
int tmpCardNum;
for(int i=poker.length-1;i>=1;i--){
tmpCardNum=tmpCardRandom.nextInt(i);
tmpCord=poker[i];
poker[i]=poker[tmpCardNum];
poker[tmpCardNum]=tmpCord;
}
}
}
package poker;
public class PokerDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Poker myPoker=new Poker();
Card[] myCard=new Card[54];
myCard=myPoker.GetPoker();
for(int i=0;i<54;i++){
System.out.println(myCard[i].GetCard());
}
System.out.println("over");
myPoker.Shuffle();
myCard=myPoker.GetPoker();
for(int i=0;i<54;i++){
System.out.println(myCard[i].GetCard());
}
}
}
package poker;public class Card { protected int color; protected int number; public static final int HEART = 0; public static final int SPADE = 1; public static final int CLUB = 2; public sta