需求: 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] 我希望我的代码可以实现 帮我改一下代码 中文解释 中文详细注释
- 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);
}