简体   繁体   中英

Using a 2d Array with random generator objective c and c++

Basically I've made a system so far that loads a random page from a directory that I specify. This works ok. But the problem with this is that I can only load one direcotry and what I want to do involves using several directories. What I have been doing so far is this.

NsArray *filelist = [filemanager direcotryContentsAtPath:@"Filler"];

I need this directory to change So I thought about a 2d array. So for example I'd declare an array like so

NsArray *filelist = [int FolderNumber] [directoryContentsAtPath:direcotry];

There's a few problems with this method though.

The way my current system of creating a random method works is by creating a number, my program then loads the file associated by that number swaps the used number with the number at the last index of the array and then deletes it to stop the number being repeated. When the array is empty the game won't load any more pages. This surely won't work with a 2-d array method I'm thinking above as if each folder has varying amount of files the game won't be able to load anything once all files have been used. Or would the compiler think the array is empty anyway?

If anybody could think of a better method I'll be glad to hear it.

I also have to work out a way of counting the folders as well but this is a much more minor point.

Any help would be appreciated.

如果使用NSMutableArray ,则可以使用addObject:通过添加NSArray从技术上创建2D数组,并且可以使用removeObjectAtIndex:删除使用的Array项

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM