private static IEnumerator destroyQueuedBlocks() /* Destroy all the player blocks that were queued up to be destroyed during mass-spreading. */ { List <Block> blocksToBeDestroyed = getBlocksQueuedToBeDestroyed(); foreach (Block block in blocksToBeDestroyed) { // Destroy the block, triggering any on destroy effects of that block. Vector2 gridIndices = block.gridIndices; block.destroy(); yield return(Pointer.displayPointer(gridIndices, "Destroy")); // Execute any on destroy effects of block combos that involved that block. if (blockCombosKeyedByBlock.ContainsKey(block)) { List <BlockCombo> blockCombos = blockCombosKeyedByBlock[block]; foreach (BlockCombo blockCombo in blockCombos) { if (BlockCombo.hasDestroyEffect(blockCombo.blockComboType)) { blockCombo.onBlockDestroy(block); yield return(Pointer.displayPointer(gridIndices, "Combo Destroy")); } } } } }
/* HELPERS */ private static List <BlockCombo> productionLineCombosAnchoredAt(Vector2 gridIndices) /* Look for the production line combo at this square. * * :param Vector2 gridIndices: * * :returns List<BlockCombo>: */ { List <BlockCombo> combos = new List <BlockCombo>(); BlockType?blockTypeHere = TrialLogic.getBlockTypeOfSquare(gridIndices); if (Block.isProductive(blockTypeHere)) { // Check from here going down. List <Block> sameTypeBlocksDown = new List <Block>(); foreach (int yIdx in Enumerable.Range((int)gridIndices.y - 3, 4)) { Vector2 otherSquare = new Vector2(gridIndices.x, yIdx); BlockType?blockTypeThere = TrialLogic.getBlockTypeOfSquare(otherSquare); if (blockTypeThere == blockTypeHere) { Block block = TrialLogic.placedBlocks[otherSquare]; sameTypeBlocksDown.Add(block); } } if (sameTypeBlocksDown.Count == 4) { BlockCombo combo = new BlockCombo( sameTypeBlocksDown, BlockComboType.PRODUCTION_LINE ); combos.Add(combo); } // Check from here going right. List <Block> sameTypeBlocksRight = new List <Block>(); foreach (int xIdx in Enumerable.Range((int)gridIndices.x, 4)) { Vector2 otherSquare = new Vector2(xIdx, gridIndices.y); BlockType?blockTypeThere = TrialLogic.getBlockTypeOfSquare(otherSquare); if (blockTypeThere == blockTypeHere) { Block block = TrialLogic.placedBlocks[otherSquare]; sameTypeBlocksRight.Add(block); } } if (sameTypeBlocksRight.Count == 4) { BlockCombo combo = new BlockCombo( sameTypeBlocksRight, BlockComboType.PRODUCTION_LINE ); combos.Add(combo); } } return(combos); }
private static void findAndStoreBlockCombos() /* Search the grid for all block combos that exist this turn, and store them in a few ways for * easy lookup. * * Populate blockCombosKeyedByAnchor and blockCombosKeyedByBlock. */ { blockCombosKeyedByAnchor = new Dictionary <Vector2, List <BlockCombo> >(); blockCombosKeyedByBlock = new Dictionary <Block, List <BlockCombo> >(); foreach (int xIdx in Enumerable.Range(0, numGridSquaresWide)) { foreach (int yIdx in Enumerable.Range(0, numGridSquaresDeep)) { Vector2 gridIndices = new Vector2(xIdx, yIdx); List <BlockCombo> combosAnchoredOnSquare = BlockCombo.combosAnchoredAt(gridIndices); blockCombosKeyedByAnchor[gridIndices] = combosAnchoredOnSquare; foreach (BlockCombo blockCombo in combosAnchoredOnSquare) { foreach (Block block in blockCombo.blocks) { if (blockCombosKeyedByBlock.ContainsKey(block)) { blockCombosKeyedByBlock[block].Add(blockCombo); } else { blockCombosKeyedByBlock[block] = new List <BlockCombo> { blockCombo }; } } } } } }
private static List <BlockCombo> getProductiveCombos() /* Get a list of all productive combos, in standard order. * * :returns List<Vector2> productiveCombos: */ { List <BlockCombo> productiveCombos = new List <BlockCombo>(); foreach (List <BlockCombo> blockCombos in blockCombosKeyedByAnchor.Values) { foreach (BlockCombo blockCombo in blockCombos) { if (BlockCombo.isProductive(blockCombo.blockComboType)) { productiveCombos.Add(blockCombo); } } } productiveCombos = MiscHelpers.standardOrder(productiveCombos, pc => pc.getAnchorSquare()); return(productiveCombos); }
private static List <BlockCombo> checkerCombosAnchoredAt(Vector2 gridIndices, BlockComboType blockComboType) /* Look for the checker combos at this square, for a certain pair of block types. * * :param Vector2 gridIndices: * :param BlockType[] blockTypes: Pair of block types we are checking for. Must be length 2. * * :returns List<BlockCombo>: */ { List <BlockCombo> combos = new List <BlockCombo>(); BlockType[] blockTypes; if (blockComboType == BlockComboType.CHECKER_BLUE_YELLOW) { blockTypes = new BlockType[2] { BlockType.BLUE, BlockType.YELLOW }; } else if (blockComboType == BlockComboType.CHECKER_BLUE_RED) { blockTypes = new BlockType[2] { BlockType.BLUE, BlockType.RED }; } else if (blockComboType == BlockComboType.CHECKER_YELLOW_RED) { blockTypes = new BlockType[2] { BlockType.YELLOW, BlockType.RED }; } else { // Invalid BlockComboType was passed in. return(combos); } BlockType?blockTypeA = TrialLogic.getBlockTypeOfSquare(gridIndices); // If this square doesn't have one of the block types we're checking for, return no combos. if (blockTypeA == null || !blockTypes.Contains((BlockType)blockTypeA)) { return(combos); } BlockType blockTypeB = blockTypeA == blockTypes[0] ? blockTypes[1] : blockTypes[0]; Vector2 topRight = new Vector2(gridIndices.x + 1, gridIndices.y); Vector2 bottomLeft = new Vector2(gridIndices.x, gridIndices.y - 1); Vector2 bottomRight = new Vector2(gridIndices.x + 1, gridIndices.y - 1); bool isAMatch = ( TrialLogic.getBlockTypeOfSquare(topRight) == blockTypeB && TrialLogic.getBlockTypeOfSquare(bottomLeft) == blockTypeB && TrialLogic.getBlockTypeOfSquare(bottomRight) == blockTypeA ); // If the 4 squares aren't the combo we're looking for, return no combos. if (!isAMatch) { return(combos); } List <Block> blocks = new List <Block> { TrialLogic.placedBlocks[gridIndices], TrialLogic.placedBlocks[topRight], TrialLogic.placedBlocks[bottomLeft], TrialLogic.placedBlocks[bottomRight] }; BlockCombo combo = new BlockCombo(blocks, blockComboType); combos.Add(combo); return(combos); }