Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest that for each collection of squares that are logically joined together you create an instance of something like:</p> <pre><code>private class TileRef { public Tile tile; public int X,Y,Width,Height;} </code></pre> <p>Then have either a 2-dimensional or jagged array of TileRef. All of the squares in a joined-together group should hold a reference to the same <code>TileRef</code> object. That should allow you to very quickly find the <code>TileRef</code> associated with any square on the board without need for conditional logic to deal with different-sized tiles.</p> <p>To construct a grid of size-one tiles:</p> <pre><code>TileRef[,] tiles; TileMapper(int xsize, int ysize) { tiles = new TileRef[xsize,ysize]; for (int x=0; x &lt; xsize; x++) for (int y=0; y &lt; xsize; y++) { var thisRef = new TileRef(); thisRef.X = x; thisRef.Y = y; thisRef.Width = 1; thisRef.Height = 1; thisRef.Tile = new Tile(); // Make a default tile instance somehow tiles[x][y] = thisRef; } } To join a bunch of squares together into a blob: public JoinSquares(int x, int y, int width, int height) { var thisRef = new TileRef(); thisRef.X = x; thisRef.Y = y; thisRef.Width = 1; thisRef.Height = 1; thisRef.Tile = new Tile(); // Make a default tile instance somehow for (i=0; i&lt;width; i++) for (j=0; j&lt;height; j++) tiles[x+i,y+j] = thisRef; } public SeparateSquares(int x, int y) { var oldRef = tiles[x,y]; x=oldref.X; y=oldref.Y; var width=oldref.Width; var height=oldref.Height; for (i=0; i&lt;width; i++) for (j=0; j&lt;height; j++) { var thisRef = new TileRef(); thisRef.X = x+i; thisRef.Y = y+j; thisRef.Width = 1; thisRef.Height = 1; thisRef.Tile = new Tile(); // Make a default tile instance somehow tiles[x+i,y+j] = thisRef; } } To change the `Tile` associated with a "blob", simply public Tile this[int x, int y] { get { return tiles[x,y].Tile; } set { tiles[x,y].Tile = value; } } </code></pre> <p>Loops are required to join squares together or separate them, but not to simply change the attributes associated with a blob by changing its <code>Tile</code> property.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload