开发者

Game Development - Array with pointers to array elements

I am currently developing a game for the iPhone/iPod/iPad. To store the board data, which is 12 columns by 8 rows, I have an array that stores pointers to one of the game items, a block. It is declared as follows:

BlockData* mBoard[开发者_StackOverflow中文版kNumberOfColumns][kNumberOfRows];

I also have another array declared like this:

BlockData* mCenterSquare[16];

This I want to store pointers to specific locations on the board, for example,

mCenterSquare[0] = mBoard[4][5];

Is this the right way of doing it? What I want to accomplish using the above line of code is for mCenterSquare[0] to store a pointer to a position on the board - 4th column and 5th row. How would I go about doing this?

Thanks in advance.


Why not only use the mCenterSquare array to store data:

function BlockData* getBlockData(int row, int col) {
     return mCenterSquare[row * kNumberOfCols + col]
}


I can't help but think this is a trick question. Yes, that is the way you would do it. :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜