0

I am planning a kids' version of Mahjong Solitaire (starting with just the Turtle board layout and working my way from there). I am trying to wrap my head around how to store the data for each layer of the Turtle layout tileset. See here for an example: http://icarus.cs.weber.edu/~dab/cs3230/labs/lab.5/tile_layers.pdf

Ordinarily I'd use a 2D array for each layer, and a 1D array of the layers, from 0 (bottom-most) to 4 (topmost), with the allowance for layers above that (5, 6, ...). However, there are the tiles that occupy more than one row and/or column at once. For example, in Layer 0 (bottom-most), the far left tile and the 2 far right tiles occupy two rows at once, and the single tile in Layer 4 (topmost) occupies two columns and two rows at the same time.

What is the best data model to store this sort of tileset? Should each tile have a flag for shifting it halfway into the next row and column?

I'm thinking, there is a Tile object, each instance of which represents 1 of the 144 tiles on the board. Then all tiles are arranged in layers as I described above (2D array for each layer, all layers stored in a 1D array).

Note: I am considering using Javascript & HTML5 for this project. It won't be something I release to the public, just a programming exercise.

Is this the best method? Am I missing something?

4

2 回答 2

2

我确实会像 alikox 建议的那样使用更精细的网格。我会使用 2 倍细的网格,给每个图块一个唯一的 id,所以一个常规图块现在使用网格的四个正方形,当你必须删除一个图块时,你只需要检查具有相同 id 的周围正方形并删除他们也是。

于 2014-06-04T14:36:15.757 回答
1

实现这一点的方法不止一种,例如,您可以设置每个图块的 x、y 和 z 坐标。

class Tile {
    int x
    int y
    int z
}
于 2014-06-03T16:45:56.123 回答