继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

扑克游戏1:扑克创建与刷新

芝麻捡了西瓜
关注TA
已关注
手记 1
粉丝 3
获赞 0
package pokergame;
import java.util.ArrayList;
import java.util.Collections;

public class BlackJack {
    private static ArrayList<StringBuffer> poker = new ArrayList<StringBuffer>();

    private BlackJack() {
    }
    //静态方法初始化扑克并返回扑克
    public static ArrayList<StringBuffer> getPoker() {
        if (!poker.isEmpty())
            poker.clear();

        for (Integer i = 2; i < 15; i++) {
            for (int j = 1; j < 5; j++) {
                switch (j) {
                case 1:
                    poker.add(new StringBuffer("方块" + i.toString()));
                    break;
                case 2:
                    poker.add(new StringBuffer("梅花" + i.toString()));
                    break;
                case 3:
                    poker.add(new StringBuffer("红桃" + i.toString()));
                    break;
                case 4:
                    poker.add(new StringBuffer("黑桃" + i.toString()));
                }
            }
        }
        for (StringBuffer s : poker) {
            if (s.lastIndexOf("11") != -1) {
                s.replace(2, 4, "J");
            }
            if (s.lastIndexOf("12") != -1) {
                s.replace(2, 4, "Q");
            }
            if (s.lastIndexOf("13") != -1) {
                s.replace(2, 4, "K");
            }
            if (s.lastIndexOf("14") != -1) {
                s.replace(2, 4, "A");
            }
        }
        Collections.shuffle(poker);
        return poker;
    }
    //刷新poker(pool是发出去的牌,在Player类中)
    public static void refresh() {
        poker.addAll(Player.pool);
    }
}
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP