internal void InitializeAdjacentTile(GameViewModel vm) { //Do nothing if this tile is bomb, as adjacent tiles aren't needed for bombs if (Type == TileType.Bomb) { return; } //Adding adjacent tiles for (int r = Row - 1; r <= Row + 1; r++) { for (int c = Column - 1; c <= Column + 1; c++) { foreach (var tile in vm.AllTiles) { if (tile.Row == r && tile.Column == c) { if (!(tile.Row == Row && tile.Column == Column)) { AdjacentTiles.Add(tile); } break; } } } } //Setting which type of tile this is based on the count of mines near it var count = 0; foreach (var tile in AdjacentTiles) { if (tile.Type == TileType.Bomb) { count++; } } Content = count; //Setting the Type of tile based on the number of bomb mines near it if (count == 0) { Type = TileType.None; } else { Type = TileType.Number; } }
private static void FillTile(AdjacentTiles t) { if ((t.tile.flags & (uint)VesselTile.FLAGS.SOLID_BLOCK) > 0) { t.tile.c0 = null; t.tile.c1 = null; } //take the compartments from left or bottom no matter what in these cases if ((t.bTile != null && t.bTile.Contains(WallTypeMask.OneByTwo)) || (t.brTile != null && t.brTile.Contains(WallTypeMask.OneByTwoFlipped))) { t.tile.c0 = t.bTile.c0.Instance; t.tile.c1 = t.bTile.c1.Instance; return; } if ((t.lTile != null && t.lTile.Contains(WallTypeMask.TwoByOne)) || (t.rTile != null && t.rTile.Contains(WallTypeMask.TwoByOneFlipped))) { t.tile.c0 = t.lTile.c0.Instance; t.tile.c1 = t.lTile.c1.Instance; return; } // //try take from bottom Compartment b = null; if (t.bTile != null) { if ((t.bTile.flags & (uint)VesselTile.FLAGS.SOLID_BLOCK) > 0) b = null; else if (!t.tile.Contains(WallTypeMask.OneByZero)) { //set the appropriate compartment field depending on how "bTile" is cut if ( (t.blTile != null && t.blTile.Contains(WallTypeMask.TwoByOne)) || (t.bTile.Contains(WallTypeMask.OneByOne)) || (t.b2Tile != null && t.b2Tile.Contains(WallTypeMask.OneByTwo))) { b = t.bTile.c1.Instance; //} else if ( // (t.b2rTile != null && t.b2rTile.Contains(WallTypeMask.OneByTwoFlipped)) || // (t.brTile != null && t.brTile.Contains(WallTypeMask.OneByOneFlipped)) || // (t.br2Tile != null && t.br2Tile.Contains(WallTypeMask.TwoByOneFlipped))){ // b = t.bTile.c0.Instance; } else { b = t.bTile.c0.Instance; } } } Compartment l = null; if (t.lTile != null) { if ((t.lTile.flags & (uint)VesselTile.FLAGS.SOLID_BLOCK) > 0) l = null; else if (!t.tile.Contains(WallTypeMask.ZeroByOne)) { l = t.lTile.c0.Instance; } } if ( (t.r2Tile != null && t.r2Tile.Contains(WallTypeMask.TwoByOneFlipped)) || (t.rTile != null && t.rTile.Contains(WallTypeMask.OneByOneFlipped | WallTypeMask.OneByTwoFlipped))) { if (l != null && b != null) { l.Combine(b); } if (b != null) { t.tile.c1 = b; } else if (l != null) { t.tile.c1 = l; } t.tile.c0 = new Compartment(); return; } else if (t.tile.Contains(WallTypeMask.TwoByOne | WallTypeMask.OneByOne | WallTypeMask.OneByTwo)) { if (b == null) { b = new Compartment(); } t.tile.c0 = b; if (l == null) { l = new Compartment(); } t.tile.c1 = l; return; } else { if (l != null && b != null) { l.Combine(b); } l = (l == null) ? b : l; if (l == null) { l = new Compartment(); } t.tile.c0 = l.Instance; } }
public void RebuildCompartments() { Vec2i start = ChunkIToTileI(aabb.bl); Vec2i end = ChunkIToTileI(aabb.tr); AdjacentTiles at = new AdjacentTiles(this); for (int i = start.y; i < end.y; i++) { at.Reset(new Vec2i(start.x, i)); for (int j = start.x; j < end.x; j++) { if (at.tile != null) { FillTile(at); } at.MoveRight(); } } return; }