1

テキスト ファイルから読み取ってタイル マップを作成しようとしていますが、rowSize (28) およびcolumnSize (19) インデックスを使用して多次元配列を作成する代わりに、rowSize (28) およびcolumnSize ²(361) インデックスを使用して作成しています。 .

テキスト ファイルには、0 と 1 の間にスペースを入れた一連の 0 と 1 が含まれているだけで、28 行が 19 行あります。

    try {
        BufferedReader findSize = new BufferedReader(new FileReader(filePath));
        String line;
        while ((line = findSize.readLine()) != null) {
            if(!line.startsWith("#")) {
                line.split("\\s");
                if(line.length() > rowSize)
                    rowSize = line.length();
                columnSize++;
            }
        }
        grid = new short[rowSize][columnSize];
        findSize.close();
    } catch(Exception e) {
        e.getMessage();
    }

    BufferedReader readTiles;
    try {
        readTiles = new BufferedReader(new FileReader(filePath));
        String line;
        short rowNum = -1;
        while ((line = readTiles.readLine()) != null) {
            if(!line.startsWith("#")) {
                rowNum++;
                String[] values = line.split("\\s");
                for(String v : values) {
                    for (short y = 0; y < grid[rowNum].length; y++) {
                        grid[rowNum][y] = Byte.parseByte(v);
                        System.out.println(grid[rowNum][y]);
                    }
                }
            }
        }
        readTiles.close();
    } catch (Exception e) {
        e.getMessage();
    }

疲れているだけなのかも知れない…

4

0 に答える 0