private void CheckMatchesDirection(ColorBlock aBlock, Point aOffset, HashSet <AbstractBlock> aMatchingBlocks) { Point blockPosition = aBlock.GetPosition(); Point offsetPosition = blockPosition + aOffset; AbstractBlock directionBlock = myGridContainer.GetBlockAtPosition(offsetPosition.X, offsetPosition.Y); if (directionBlock is ColorBlock && ((ColorBlock)directionBlock).GetColor() == aBlock.GetColor() && directionBlock.IsSwitching() == false && aBlock.IsSwitching() == false) { Point offsetOffsetPosition = blockPosition + new Point(aOffset.X * 2, aOffset.Y * 2); AbstractBlock directionDirectionBlock = myGridContainer.GetBlockAtPosition(offsetOffsetPosition.X, offsetOffsetPosition.Y); if (directionDirectionBlock is ColorBlock && ((ColorBlock)directionDirectionBlock).GetColor() == aBlock.GetColor() && directionDirectionBlock.IsSwitching() == false) { aMatchingBlocks.Add(aBlock); aMatchingBlocks.Add(directionBlock); aMatchingBlocks.Add(directionDirectionBlock); } } }
// +Player actions! public void SwapBlocksRight(Point aPosition) { AbstractBlock leftBlock = myGridContainer.GetBlockAtPosition(aPosition); AbstractBlock rightBlock = myGridContainer.GetBlockAtPosition(aPosition + new Point(1, 0)); if ((leftBlock is ColorBlock || leftBlock is EmptyBlock) && leftBlock.IsSwitching() == false) { if ((rightBlock is ColorBlock || rightBlock is EmptyBlock) && rightBlock.IsSwitching() == false) { leftBlock.SetPosition(aPosition + new Point(1, 0)); rightBlock.SetPosition(aPosition); myGridContainer.myGrid[aPosition.Y][aPosition.X].SetBlock(rightBlock); myGridContainer.myGrid[aPosition.Y][aPosition.X + 1].SetBlock(leftBlock); float magicSwitchTime = 0.66f / myModifiedGameSpeed; leftBlock.StartTheSwitchingCalculation(magicSwitchTime, ESwitchDirection.ToTheRight); rightBlock.StartTheSwitchingCalculation(magicSwitchTime, ESwitchDirection.ToTheLeft); } } }