private void calculateBlocks(Dictionary <int, int> blocks, Level level) { List <Block> block = new List <Block> (); PieceFactory factory = PieceFactory.getInstance(); foreach (KeyValuePair <int, int> entry in blocks) { PieceConfig config = factory.getConfig(entry.Key); if (config == null) { throw new System.InvalidOperationException("Piece is null"); } for (int i = 0; i < (entry.Value / config.blockCount); i++) { block.Add(makeBlock(config)); } } level.setBlocks(block.ToArray()); }