m0_65749592 2024-06-25 11:43 采纳率: 35.5%
浏览 3

万能翻倍素材翻倍及移动

需求: 1. countOnes >= 2的情况当posArr出现2个翻倍万能素材,比如 wildList里面存储的是[2_7_5, 1_8_2,5_2_1] 和 bonusList存储的是[2_7_5, 1_8_2,5_2_1] ,这两个符合合并1_8_2,5_2_1 要合并得到的这个新值2_1_16,所以之后 我要的是 更新后的 wildList:[2_7_5, 2_1_16]更新后的 bonusList:[2_7_5,2_1_16,1_8_2,5_2_1] 2. 新值2_1_16在前 是因为这两个合并1_8_2,5_2_1 ,所以要在排在新的后面位置,
再比方 假设说开始 wildList里面存储的是[0_7_5, 0_8_2, 2_3_1,0_3_1] 和 bonusList存储的是[0_7_5, 0_8_2, 2_3_1,0_3_1]。这两个符合合并0_7_5, 0_8_2, 然后这个新值是4_6_10,我需要bonusList 更新成[4_6_10,0_7_5, 0_8_2, 2_3_1,0_3_1] 和 wildList更新是[4_6_10, 2_3_1,0_3_1] 我希望我的代码可以实现 帮我改一下代码 中文解释 中文详细注释

  1. countOnes = 1 的情况当posArr已经出现1个后,万能翻倍素材再次参与消除时,翻倍素材在原翻倍基础上+1,并在消除区域随机移动一个宫格, 假设wildList里面存储的是[0_1_5, 0_2_2] 和 bonusList存储的是[0_1_5, 0_2_2] ,这其中一个符合0_1_5 新值是2_1_6,所以之后 我要的是 更新后的 wildList:[2_1_6, 0_2_2]更新后的 bonusList:[2_1_6,0_1_5, 0_2_2] 2. 新值2_1_6在前

3, 我代码不知道有什么问题 Java 语言 帮我改一下

        List<SlotGameLineData> list = getAdjacentMaterialList(matrix);//中奖位置列表
        if (list.size() > 0) {
            for (SlotGameLineData data : list) {
                String[] posArr = data.getMaterialPos().split(",");
                int countOnes = 0; // 记录一条连线有多少个  万能
                for (String position : posArr) {
                    String[] str = position.split("_");
                    int r = Integer.parseInt(str[0]);
                    int c = Integer.parseInt(str[1]);
                    if (matrix[r][c] == 1) {
                        countOnes++;
                    }
                }
                if (countOnes == 0) {// 没有万能的情况 
                     List<String> randomPosition = Arrays.asList(getRanPositions(posArr)); //随机取一个位置先存储 之后 变成万能素材
                     for (int k = 0; k < posArr.length; k++) {
                         String[] str = posArr[k].split("_");
                            int r = Integer.parseInt(str[0]);
                            int c = Integer.parseInt(str[1]);
                            matrix[r][c] = 0; // 将中奖的位置清零
                    }
                     if (randomPosition != null) {
                            for (String newPos : randomPosition) {
                                String[] newPosArr = newPos.split("_");
                                int newRow = Integer.parseInt(newPosArr[0]);
                                int newCol = Integer.parseInt(newPosArr[1]);
                                String newBonus = newRow + "_" + (newCol + matrixsBonus.size() * col) + "_" + 1;//存储万能位置
                                if (!wildList.contains(newBonus)) {
                                    if (!bonusList.contains(newBonus)) { 
                                        bonusList.add(newBonus);
                                        wildList.add(newBonus); // 添加万能位置
                                        logger.info("中奖列表 没有 万能素材 的连线情况1····" + wildList +"```bonusList"+bonusList);
                                    }
                                }
                            }
                        }
                }  
                else if (countOnes == 1) {
                    List<String> randomPosition = Arrays.asList(getRanPositions(posArr));
                    String randomPositionStr = randomPosition.get(0);
                    String[] randPosSplit = randomPositionStr.split("_");
                    int newR = Integer.parseInt(randPosSplit[0]);
                    int newC = Integer.parseInt(randPosSplit[1]);

                    String newWildValue = newR + "_" + (newC + matrixsBonus.size() * col) + "_1";

                    for (int i = 0; i < wildList.size(); i++) {
                        String wString = wildList.get(i);
                        String[] item = wString.split("_");
                        int a1 = Integer.parseInt(item[0]);
                        int b2 = Integer.parseInt(item[1]);
                        int newValue = Integer.parseInt(item[2]);

                        int c3 = b2 % 7;
                        if (b2 >= 7) {
                            int colOffset = b2 / 7;
                            c3 = b2 - 7 * colOffset;
                        }

                        if (newR == a1 && newC == c3) {
                            int valus = newValue + 1;

                            wildList.set(i, newWildValue);
                            bonusList.add(bonusList.indexOf(wString) + 1, newWildValue);

                            logger.info("中奖列表有 1 个万能素材的连线情况2 wildList····" + wildList);
                            logger.info("中奖列表有 1 个万能素材的连线情况2 bonusList····" + bonusList);

                            break;
                        }
                    }

                    for (String position : posArr) {
                        String[] str = position.split("_");
                        int r = Integer.parseInt(str[0]);
                        int c = Integer.parseInt(str[1]);

                        matrix[r][c] = 0;
                    }
                }


                 //当中奖    列表里面有   两个或者多个   万能素材的时候
                else  
                    if (countOnes >= 2) {
                        // 清空中奖位置
                        for (String position : posArr) {
                            String[] str = position.split("_");
                            int r = Integer.parseInt(str[0]);
                            int c = Integer.parseInt(str[1]);
                            matrix[r][c] = 0;
                        }
                        List<String> newBonusList = new ArrayList<String>();
                        List<Integer> multiplierValues = new ArrayList<Integer>();
                        // 遍历中奖位置,匹配wildList中的位置,并计算乘数值
                        for (String position : posArr) {
                            String[] str = position.split("_");
                            int r = Integer.parseInt(str[0]);
                            int c = Integer.parseInt(str[1]);

                            for (String wildPosition : wildList) {
                                String[] wildStr = wildPosition.split("_");
                                int wildR = Integer.parseInt(wildStr[0]);
                                int wildC = Integer.parseInt(wildStr[1]);

                                if (wildC >= 7) {
                                    wildC = wildC % 7;
                                }
                                if (r == wildR && c == wildC) {
                                    int multiplier = Integer.parseInt(wildStr[2]); 
                                    multiplierValues.add(multiplier);
                                    break;
                                }
                            }
                        }
                        // 计算乘积
                        int product = 1;
                        for (int value : multiplierValues) {
                            product *= (value + 1);
                        }

                        // 生成随机位置
                        Random random = new Random();
                        String randomPosition = posArr[random.nextInt(posArr.length)];
                        String[] randomStr = randomPosition.split("_");
                        int randomR = Integer.parseInt(randomStr[0]);
                        int randomC = Integer.parseInt(randomStr[1]);

                        // 更新bonusList
                        newBonusList.add(randomPosition + "_" + product);

                        // 将不在posArr中的wildPosition添加到newBonusList
                        for (String wildPosition : wildList) {
                            if (!Arrays.asList(posArr).contains(wildPosition)) {
                                newBonusList.add(wildPosition);
                            }
                        }

                        bonusList.clear(); // 清空原有列表
                        bonusList.addAll(newBonusList); // 将新列表元素加入bonusList

                        List<String> newWildList = new ArrayList<String>();
                        newWildList.add(randomPosition + "_" + product);

                        // 更新wildList
                        for (String position : posArr) {
                            boolean found = false;

                            for (String wildPosition : wildList) {
                                if (position.equals(wildPosition)) {
                                    newWildList.add(wildPosition);
                                    found = true;
                                    break;
                                }
                            }

                            if (!found) {
                                newWildList.add(position);
                            }
                        }

                        wildList.clear();
                        wildList.addAll(newWildList);
                    }



        }
            matrixCHUANSONMEN(matrix, noBingo);
    }

  • 写回答

2条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-06-25 11:43
    关注

    引自免费微信小程序:皆我百晓生

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    public class Main {
        public static void main(String[] args) {
            // 测试代码
            testCode();
        }
    
        private static void testCode() {
            List<SlotGameLineData> list = getAdjacentMaterialList(matrix);
            if (list.size() > 0) {
                for (SlotGameLineData data : list) {
                    String[] posArr = data.getMaterialPos().split(",");
                    int countOnes = 0; // 记录一条连线有多少个  万能
                    for (String position : posArr) {
                        String[] str = position.split("_");
                        int r = Integer.parseInt(str[0]);
                        int c = Integer.parseInt(str[1]);
                        if (matrix[r][c] == 1) {
                            countOnes++;
                        }
                    }
                    if (countOnes == 0) {
                        // 没有万能的情况 
                        List<String> randomPosition = Arrays.asList(getRanPositions(posArr));
                        for (String newPos : randomPosition) {
                            String[] newPosArr = newPos.split("_");
                            int newRow = Integer.parseInt(newPosArr[0]);
                            int newCol = Integer.parseInt(newPosArr[1]);
                            String newBonus = newRow + "_" + (newCol + matrixsBonus.size() * col) + "_" + 1;
                            if (!wildList.contains(newBonus)) {
                                if (!bonusList.contains(newBonus)) {
                                    bonusList.add(newBonus);
                                    wildList.add(newBonus); // 添加万能位置
                                }
                            }
                        }
                    } else if (countOnes == 1) {
                        // 当一条连线包含1个万能素材的情况
                        List<String> randomPosition = Arrays.asList(getRanPositions(posArr));
                        String randomPositionStr = randomPosition.get(0);
                        String[] randPosSplit = randomPositionStr.split("_");
                        int newR = Integer.parseInt(randPosSplit[0]);
                        int newC = Integer.parseInt(randPosSplit[1]);
                        String newWildValue = newR + "_" + (newC + matrixsBonus.size() * col) + "_1";
                        for (int i = 0; i < wildList.size(); i++) {
                            String wString = wildList.get(i);
                            String[] item = wString.split("_");
                            int a1 = Integer.parseInt(item[0]);
                            int b2 = Integer.parseInt(item[1]);
                            int newValue = Integer.parseInt(item[2]);
    
                            int c3 = b2 % 7;
                            if (b2 >= 7) {
                                int colOffset = b2 / 7;
                                c3 = b2 - 7 * colOffset;
                            }
    
                            if (newR == a1 && newC == c3) {
                                int valus = newValue + 1;
    
                                wildList.set(i, newWildValue);
                                bonusList.add(bonusList.indexOf(wString) + 1, newWildValue);
    
                                logger.info("中奖列表 没有 万能素材 的连线情况1····" + wildList +"```bonusList"+bonusList);
                            }
                        }
    
                        for (String position : posArr) {
                            String[] str = position.split("_");
                            int r = Integer.parseInt(str[0]);
                            int c = Integer.parseInt(str[1]);
    
                            matrix[r][c] = 0;
                        }
                    } else if (countOnes >= 2) {
                        // 当两条或多条连线包含2个及以上万能素材的情况
                        List<String> newBonusList = new ArrayList<String>();
                        List<Integer> multiplierValues = new ArrayList<Integer>();
                        for (String position : posArr) {
                            String[] str = position.split("_");
                            int r = Integer.parseInt(str[0]);
                            int c = Integer.parseInt(str[1]);
    
                            for (String wildPosition : wildList) {
                                String[] wildStr = wildPosition.split("_");
                                int wildR = Integer.parseInt(wildStr[0]);
                                int wildC = Integer.parseInt(wildStr[1]);
    
                                if (wildC >= 7) {
                                    wildC = wildC % 7;
                                }
                                if (r == wildR && c == wildC) {
                                    int multiplier = Integer.parseInt(wildStr[2]); 
                                    multiplierValues.add(multiplier);
                                    break;
                                }
                            }
                        }
                        int product = 1;
                        for (int value : multiplierValues) {
                            product *= (value + 1);
                        }
    
                        // 生成随机位置
                        Random random = new Random();
                        String randomPosition = posArr[random.nextInt(posArr.length)];
                        String[] randomStr = randomPosition.split("_");
                        int randomR = Integer.parseInt(randomStr[0]);
                        int randomC = Integer.parseInt(randomStr[1]);
    
                        // 更新bonusList
                        newBonusList.add(randomPosition + "_" + product);
    
                        // 将不在posArr中的wildPosition添加到newBonusList
                        for (String wildPosition : wildList) {
                            if (!Arrays.asList(posArr).contains(wildPosition)) {
                                newBonusList.add(wildPosition);
                            }
                        }
    
                        bonusList.clear(); // 清空原有列表
                        bonusList.addAll(newBonusList); // 将新列表元素加入bonusList
    
                        List<String> newWildList = new ArrayList<String>();
                        newWildList.add(randomPosition + "_" + product);
    
                        // 更新wildList
                        for (String position : posArr) {
                            boolean found = false;
    
                            for (String wildPosition : wildList) {
                                if (position.equals(wildPosition)) {
                                    newWildList.add(wildPosition);
                                    found = true;
                                    break;
                                }
                            }
    
                            if (!found) {
                                newWildList.add(position);
                            }
                        }
    
                        wildList.clear();
                        wildList.addAll(newWildList);
                    }
                }
            }
        }
    
        private static List<SlotGameLineData> getAdjacentMaterialList(int[][] matrix) {
            List<SlotGameLineData> result = new ArrayList<>();
            for (int row = 0; row < matrix.length; row++) {
                for (int col = 0; col < matrix[row].length; col++) {
                    if (matrix[row][col] == 1) {
                        SlotGameLineData slotGameLineData = new SlotGameLineData(row, col);
                        result.add(slotGameLineData);
                    }
                }
            }
            return result;
        }
    
        private static List<String> getRanPositions(List<String> positions) {
            List<String> result = new ArrayList<>();
            Random random = new Random();
            for (String position : positions) {
                int index = random.nextInt(position.length());
                String newPos = position.substring(index);
                result.add(newPos);
            }
            return result;
        }
    
        private static void matrixCHUANSONMEN(int[][] matrix, List<String> noBingo) {
            // 其他逻辑代码
        }
    }
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 6月25日

悬赏问题

  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错