不多说,附上代码。 CardFactory类 package org.alies.card; import java.lang.reflect.Array; import java.util.Random; public class CardFactory { private static Card[] cards; private static int currnt; private static int length = 54; // 获得一个实例 public Card getInstance(int r,int c) { Card card = new Card(r,c); return card; } // 初始化 public void init() { cards = new Card[length]; int i = 0; currnt = 0; while (currnt < length) { if (currnt % 13 == 0) { i++; } cards[currnt] = getInstance(i,currnt % 13 + 1); currnt++; } } // 获得一个元素 public synchronized Card getCard() { Random rm = new Random(); int cursor = 0; if (length > 1) cursor = rm.nextInt(length - 1); System.out.println(cursor); Card c = null; try { c = cards[cursor]; romeCard(c); }catch (ArrayIndexOutOfBoundsException e) { System.out.println("数组下表越界错误!"); } return c; } // 删除一个元素 private void romeCard(Card card) { int cursor = 0; if (card != null) for (int i = 0; i < length; i++) if (cards[i] != null) if (cards[i].getCardType() == card.getCardType() && cards[i].getCardValue() == card.getCardValue()) { // 测试代码 // System.out.println(i); cursor = i; } length -= 1; Card[] temp = new Card[length]; System.arraycopy(cards,0,temp,0,cursor);// 复制前面 System .arraycopy(cards,cursor + 1,temp,cursor,cards.length - cursor - 1);// 复制后面 cards = new Card[length]; cards = temp; // *测试的代码 int r = 0; for (Card c : temp) { if (r == 13) { r = 0; System.out.println(); } r++; System.out.print(c + " "); } System.out.println("本次发牌结束!"); } } Card类 package org.alies.card; public class Card { private int cardType = 0; private int cardValue = 0; public Card(int type,int value) { this.cardType = type; this.cardValue = value; } public int getCardType() { return cardType; } public void setCardType(int cardType) { this.cardType = cardType; } public int getCardValue() { return cardValue; } public void setCardValue(int cardValue) { this.cardValue = cardValue; } @Override public String toString() { String outter = "[" + this.getCardType() + "," + this.getCardValue() + "]"; return outter; } } Player类 package org.alies.card; public class Player { private String plName = "";// 玩家姓名 private int plType = 0; // 玩家类别 private Card[] plCards; private int length = 17; //玩家用用牌的数量 private int statr_cursor; // 选中开始位置 private int end_cursor; // 选中结束位置 private CardFactory factory; // 默认构造 public Player(CardFactory factory) { this.factory = factory; this.plName = "NPC"; } public Player(CardFactory factory,String str) { this.factory = factory; this.plName = str; } // 取牌 public void getCard() { plCards = new Card[length]; // 获取17张牌 int i = 0; for (; i < length; i++) { plCards[i]=factory.getCard(); } sort(); } // 打牌 public boolean putCard() { sort(); return false; } // 排序 位置 private void sort() { // 冒泡 int i = 0; int j = 0; Card temp = null; // 判断类别是否一样 for (; i < plCards.length; i++) for (; j < plCards.length - i - 1; j++) if (plCards[j].getCardType() == plCards[j + 1].getCardType()) if (plCards[j].getCardValue() > plCards[j + 1] .getCardValue()) { temp = plCards[j]; plCards[j] = plCards[j + 1]; plCards[j + 1] = temp; } } @Override public String toString() { int i = 0; StringBuilder sbd = new StringBuilder(); sbd.append("玩家:"+this.plName+" "); sbd.append("类别"+this.plType+" "); for (; i < plCards.length; i++) { if (i % 13 == 0) {// 换行 System.out.println(); } sbd.append(plCards[i] + " "); } return sbd.toString(); } } Main类 package org.alies.card; public class Main { public static void main(String[] args) { //获得纸牌 CardFactory factory = new CardFactory(); factory.init(); Player p0 = new Player(factory); Player p1 = new Player(factory); Player p2 = new Player(factory,"jack"); p0.getCard(); p1.getCard(); p2.getCard(); System.out.println(p0); System.out.println(p1); System.out.println(p2); } } 稍后将有进一步动作。