/// <summary> /// checks for adjacent tiles, and sends them onward in a List of Tiles. /// </summary> /// <param name="tile">(Tile) The newly placed tile / "connector tile".</param> /// <returns>(List of Tile) A list of adjacent tiles, possibly empty. </returns> private List <Tile> getAdjacentTiles(Tile tile) { // checks for edge cases. List <Tile> adjacents = new List <Tile>(); Tuple <int, int> pos = convertPositionToGrid(tile.getPosition()); int row = pos.Item1; int col = pos.Item2; if (row != 0)//find top tile { // if the tile has been placed... if (board[row - 1, col] != null) { adjacents.Add(board[row - 1, col]); } } if (row != Board.MAX_ROWS - 1)//find bottom tile { // if the tile has been placed... if (board[row + 1, col] != null) { adjacents.Add(board[row + 1, col]); } } if (col != 0)//find left tile { // if the tile has been placed... if (board[row, col - 1] != null) { adjacents.Add(board[row, col - 1]); } } if (col != Board.MAX_COLUMNS - 1)//find right tile { // if the tile has been placed... if (board[row, col + 1] != null) { adjacents.Add(board[row, col + 1]); } } // Returns a possibly empty List return(adjacents); }
/// <summary> /// Plays the tile on the board. It may cause several different events to occur. /// </summary> /// <param name="tile">The tile object to play.</param> /// <returns>TileIntersection: object containing surrounding tiles, or null if there were no surrounding tiles.</returns> public TileIntersection playTile(Tile tile) { // Get row and column on the board grid var tuple = this.convertPositionToGrid(tile.getPosition()); // Put the tile on the board board[tuple.Item1, tuple.Item2] = tile; // Forms a corporation, if possible. List <Tile> adjTiles = getAdjacentTiles(tile); if (adjTiles.Count > 0) { TileIntersectionFactory factory = new TileIntersectionFactory(); return(factory.determineIntersection(tile, adjTiles)); } return(null); }