public static Puzzle CreateFromLevelTemplate(LevelTemplate levelTemplate, PuzzleCreationContext context) { var shapes = new List <Shape>(); foreach (var shapeData in levelTemplate.Shapes) { var shape = Shape.Create(shapeData.TilePositions, new Vector2(shapeData.OffsetX, shapeData.OffsetY), context.Storyboard, context.TileModel, context.Palette, -100); shapes.Add(shape); } AdjustInitialPositionsToCentreShape(shapes); AssignExplodedPositions(shapes, context.LayoutSize); var numberOfMoves = Math.Min(shapes.Count + (int)Math.Ceiling(context.Hardness * shapes.Count) - 1, 2 * shapes.Count); var deformations = GetDeformationSequence(shapes).Take(numberOfMoves).ToList(); return(new Puzzle(context.Storyboard, shapes, deformations)); }
public static Puzzle CreateFromPuzzleData(PuzzleDto puzzleData, PuzzleCreationContext context) { var shapes = new List <Shape>(); foreach (var shapeData in puzzleData.LevelTemplate.Shapes) { var shape = Shape.Create(shapeData.TilePositions, new Vector2(shapeData.OffsetX, shapeData.OffsetY), context.Storyboard, context.TileModel, context.Palette, -100); shapes.Add(shape); } AdjustInitialPositionsToCentreShape(shapes); AssignExplodedPositions(shapes, context.LayoutSize); var deformations = puzzleData.Deformations.Select( deformation => new ShapeDeformation() { Shape = shapes[deformation.ShapeIndex], Deformation = GetDeformationClassFromDto(deformation.Transformation), }).ToList(); return(new Puzzle(context.Storyboard, shapes, deformations)); }