0

好的,我的 android 游戏运行流畅,但无法升级。我也收到此警告:说明资源路径位置类型类型安全:方法 addElement(Object) 属于原始类型 Vector。对泛型类型 Vector 的引用应该参数化 LevelManager.java/FROZEN BUBBLES/src/org/bigdaddyapp/android/frozenbubbles 第 32 行 Java 问题

import android.os.Bundle;
import java.util.Vector;

public class LevelManager {
private int currentLevel;
private Vector levelList;

public void saveState(Bundle map) {
    map.putInt("LevelManager-currentLevel", currentLevel);
}

public void restoreState(Bundle map) {
    currentLevel = map.getInt("LevelManager-currentLevel");
}

public LevelManager(byte[] levels, int startingLevel) {
    String allLevels = new String(levels);

    currentLevel = startingLevel;
    levelList = new Vector();

    int nextLevel = allLevels.indexOf("\n\n");
    if (nextLevel == -1 && allLevels.trim().length() != 0) {
        nextLevel = allLevels.length();
    }

    while (nextLevel != -1) {
        String currentLevel = allLevels.substring(0, nextLevel).trim();

        levelList.addElement(getLevel(currentLevel));

        allLevels = allLevels.substring(nextLevel).trim();

        if (allLevels.length() == 0) {
            nextLevel = -1;
        } else {
            nextLevel = allLevels.indexOf("\n\n");

            if (nextLevel == -1) {
                nextLevel = allLevels.length();
            }
        }
    }

    if (currentLevel >= levelList.size()) {
        currentLevel = 0;
    }
}

private byte[][] getLevel(String data) {
    byte[][] temp = new byte[8][12];

    for (int j = 0; j < 12; j++) {
        for (int i = 0; i < 8; i++) {
            temp[i][j] = -1;
        }
    }

    int tempX = 0;
    int tempY = 0;

    for (int i = 0; i < data.length(); i++) {
        if (data.charAt(i) >= 48 && data.charAt(i) <= 55) {
            temp[tempX][tempY] = (byte) (data.charAt(i) - 48);
            tempX++;
        } else if (data.charAt(i) == 45) {
            temp[tempX][tempY] = -1;
            tempX++;
        }

        if (tempX == 8) {
            tempY++;

            if (tempY == 12) {
                return temp;
            }

            tempX = tempY % 2;
        }
    }

    return temp;
}

public byte[][] getCurrentLevel() {
    if (currentLevel < levelList.size()) {
        return (byte[][]) levelList.elementAt(currentLevel);
    }

    return null;
}

public void goToNextLevel() {
    currentLevel++;
    if (currentLevel >= levelList.size()) {
        currentLevel = 0;
    }
}

public void goToFirstLevel() {
    currentLevel = 0;
}

public int getLevelIndex() {
    return currentLevel;
}

}

4

1 回答 1

0

对于 Eclipse 环境,您会收到不使用泛型的警告,因此您应该使用

private Vector<byte[][]> levelList;

反而。

一种替代方法是关闭 Eclipse 首选项中的警告,但我不建议这样做。这些警告可以帮助您。

我还建议您创建一个类Level而不是使用byte[][].

于 2012-04-11T01:07:04.520 回答