import java.util.Collections;
import java.util.LinkedList;
/**
* 这是一副扑克
* @author Administrator
*/
public class Poker {
private LinkedList<String> poker =new LinkedList<String>();
/**
* 初始化一副有顺序的牌
*/
public Poker(){
String[] huaSe = {"方块","红心","梅花","黑桃"};
String[] dianShu = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
for (int i = 0; i < huaSe.length; i++) {
for (int j = 0; j < dianShu.length; j++) {
poker.add(huaSe[i].concat(dianShu[j]));
}
}
poker.add("小王");
poker.add("小王");
}
/**
* 洗牌方法
*/
public void shuffle(){
Collections.shuffle(poker);
}
/**
* 获得牌
* @return 当前的牌
*/
public LinkedList<String> getPoker(){
return poker;
}
/**
* 发牌方法
* @return 扑克中的第一张牌
*/
public String dealPoker(){
return poker.removeFirst();
}
}
-------------------------------------------------------------------------------------------------
import java.util.LinkedList;
public class PokerTest {
/**
* @param args
*/
public static void main(String[] args) {
LinkedList<String> playA = new LinkedList<String>();
LinkedList<String> playB = new LinkedList<String>();
LinkedList<String> playC = new LinkedList<String>();
//上扑克
Poker poker = new Poker();
//洗牌
poker.shuffle();
//洗牌
while(poker.getPoker().size()>3){
playA.add(poker.dealPoker());
playB.add(poker.dealPoker());
playC.add(poker.dealPoker());
}
//看牌
System.out.println(playA);
System.out.println(playB);
System.out.println(playC);
//看地主牌
System.out.println(poker.getPoker());
}
}
有一点小问题,怎么可以让java输出♢♣♤♡这样的字符?
|
|