} // Needed for JSON deserialization /// <summary> /// Generate a shape somewhere in the given region using the provided strategy. /// CenterPos will be set to the position of the first generated ShapeBlock /// </summary> public BaseShape(GenerationStrategy strategy, int lowerBoundX, int lowerBoundY, int upperBoundX, int upperBoundY) { var blocks = strategy.GenerateShapeBlocks(lowerBoundX, lowerBoundY, upperBoundX, upperBoundY); CenterPosX = blocks[0].OffsetX; CenterPosY = blocks[0].OffsetY; this.lowerBoundY = lowerBoundY; this.upperBoundY = upperBoundY; ShapeBlocks = GenerationStrategy.MakeRelative(blocks, CenterPosX, CenterPosY); Strategy = strategy; }
/// <summary> /// Get the first out-of-bounds ShapeBlocks, which should be sent to client. Called by host. /// </summary> public override List <ShapeBlock> GetNextBlocks() { var nextBlock = ShapeBlocks.FirstOrDefault(x => x.OffsetX >= GameSettings.HorizontalCellCount); if (nextBlock is null) { // Generate blocks for the next screen var lastBlock = ShapeBlocks.Last(); var blocks = Strategy.GenerateShapeBlocks(lastBlock.OffsetX + 1, lowerBoundY, GameSettings.HorizontalCellCount * 2, upperBoundY, lastBlock.OffsetY + CenterPosY); nextBlock = blocks.First(); ShapeBlocks.AddRange(GenerationStrategy.MakeRelative(blocks, CenterPosX, CenterPosY)); } return(ShapeBlocks.Where(x => x.OffsetX == nextBlock.OffsetX).ToList()); }