开发者

Java - Managing specific int[][]

Let's say I want to store three sets of 2D arrays that load up on int[][] board.

An example set:

{
{ 67, 67, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118 },
{ 67, 343, 343, 343, 343, 343, 343, 343, 343, 394, 1, 1, 1, 1, 1, 118 },
{ 67, 343, 448, 343, 343, 343, 343, 343, 514, 514, 1, 166, 166, 166, 1, 118 },
{ 67, 343, 343, 343, 343, 343, 430, 343, 514, 514, 1, 166, 166, 166, 1, 118 },
{ 343, 343, 343, 343, 343, 343, 343, 343, 514, 514, 1, 166, 166, 166, 1, 118 },
{ 343, 343, 343, 343, 343, 343, 343, 343, 514, 514, 439, 472, 73, 472, 469, 118 },
{ 118, 343, 343, 343, 343, 343, 343, 343, 448, 343, 343, 343, 343, 343, 343, 118 },
{ 118, 343, 448, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 118 },
{ 67, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 开发者_JAVA技巧430, 343, 343, 118 },
{ 67, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 343, 118 },
{ 67, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118 }
};

Of course, the other two sets will have different numbers. But let's say I randomly generate three of these sets and I want to load them by by, lets say, doing loadBoard(1) where 1 could be an identifier to uniquely name the map ids.

I'm not asking for code merely how I would go about approaching this. This not not a "do my assignment" but more of a "what exactly should i do".

Keep in mind, these sets will NOT be specified already in the file. They will be read from a .txt file so that will be coming in when the file loads.

Thank you.


you could try using an approach simliar to this:

class Jahkr {

    int[][] board;

    String[] filenames = new String[]{"first.txt","second.txt","third.txt"};

    loadBoard(int i) {
        Scanner sc = new Scanner(new File(filenames[i])); // 0, 1, 2 allowed
        // proceed to load the board from the file using the scanner
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜