Beispiel #1
0
        private Screen GenerateLayout(IReadOnlyList <string> layout, IDictionary <string, TileFactory> mappings)
        {
            if (layout.Count != _verticalTiles)
            {
                throw new ArgumentException($"Must have {_verticalTiles} rows");
            }

            if (layout.Any(r => r.Length != _horizontalTiles * 2))
            {
                throw new ArgumentException($"Must have {_horizontalTiles} columns");
            }

            var screen = new Screen();

            for (var yy = layout.Count - 1; yy >= 0; yy--)
            {
                var row = layout[yy];

                var y = layout.Count - 1 - yy;
                for (var xx = 0; xx < row.Length; xx += 2)
                {
                    var tile = row.Substring(xx, 2);
                    if (string.IsNullOrWhiteSpace(tile))
                    {
                        continue;
                    }

                    var tileDetails = mappings[row.Substring(xx, 2)];
                    var x           = xx / 2;
                    screen.AddTile(tileDetails.Create(x, y, tileDetails.File));
                }
            }

            return(screen);
        }