简单的抽卡模拟器1.0

       

记录非洲生活学习

    卡牌数据获取(用了jxl)

 public void setBlueCard() {
        //创建workbook
        Workbook workbook= null;
        try {
            workbook = Workbook.getWorkbook(new File("G:/JavaStudy2/cardData/blueCard.xls"));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        }
        //获取第一个工作表sheet
        Sheet sheet=workbook.getSheet(0);
        //获取数据
        for (int i=0;i<sheet.getRows();i++){
            for (int j=0;j<sheet.getColumns();j++){
                Cell cell=sheet.getCell(j,i);
                blueCard.add(cell.getContents()+"");
            }
        }

        workbook.close();

    }

    public List<String> getBlueCard() {
        return blueCard;
    }

保底设置和抽卡结果判断(太粗糙了

public class Raffle {
    private int count;
    private int countPurple;
    private int countGold;
    private double purplePercent;
    private double goldPercent;

    Raffle(){
         count = 1;
         countGold = 1;
         countPurple = 1;
         purplePercent = 0.1;
         goldPercent = 0.06;
    }


    private double getRandom(){
        return Math.random();
    }
    
//抽卡结果判断
    private String getAnswer(){
        double chance = getRandom();
        boolean isGold = getGold(chance);
        boolean isPurple = getPurple(chance);

        if(isGold){
            countGold = 1;
            goldPercent = 0.06;
            count++;
            countPurple = countPurple < 10?(countPurple+1):10;
            return "gold";
        }else if(isPurple){
            countGold++;
            count++;
            countPurple = 1;
            return "purple";
        }else{
            countPurple++;
            countGold++;
            count++;
            return "blue";
        }
    }

    private boolean getGold(double chance){
        //保底机制
        if(countGold >= 76) goldPercent += 0.08;
        return chance <= goldPercent;
    }

    private boolean getPurple(double chance){
        //保底机制
        if(countPurple == 10)return true;
        return chance <= purplePercent;
    }

抽卡流程

 private List<String> blue;
    private List<String> purple;
    private List<String> gold;
    private int blueLength;
    private int purpleLength;
    private int goldLength;

    PickCard(){
        blue = new Card().getBlueCard();
        blueLength = blue.size();

        purple = new Card().getPurpleCard();
        purpleLength = purple.size();

        gold = new Card().getGoldCard();
        goldLength = gold.size();
    }

    private double getRandom(){
        return Math.random();
    }

    public String getCard(String ans){
        if(ans.equals("gold")){
            int a = (int)(getRandom()*goldLength);
            return gold.get(a);
        }else if(ans.equals("purple")){
            int a = (int)(getRandom()*purpleLength);
            return purple.get(a);
        }else{
            int a = (int)(getRandom()*blueLength);
            return blue.get(a);
        }
    }

最后调用

public class TEST {
    Raffle raffle = new Raffle();
    PickCard pick = new PickCard();
    private void tenTimesPick(){
        int count = 10;
        while (count-- > 0){
            String color = raffle.pickCard();
            System.out.println("[" + color + "]" + pick.getCard(color));
        }
    }

    private void singlePick(){
        String color = raffle.pickCard();
        System.out.println("[" + color + "]" + pick.getCard(color));
    }

}

效果(咋还是非酋艹

加油优化

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值