private void AddTiles(IEnumerable <Tuple <string, string> > wordAndIds,
                              TextTileRow row)
        {
            int x = 1;

            foreach (var wi in wordAndIds)
            {
                TextTile tile = new TextTile
                {
                    X = x++
                };
                var textAndPatch = GetTextAndPatch(wi.Item1);
                if (textAndPatch != null)
                {
                    tile.Data["text"]  = textAndPatch.Item1;
                    tile.Data["patch"] = textAndPatch.Item2;
                }
                else
                {
                    tile.Data["text"] = wi.Item1;
                }

                tile.Data["id"] = wi.Item2;
                row.Tiles.Add(tile);
            }
        }
        private static TiledTextPart GetTiledTextPart(int rowCount)
        {
            TiledTextPart part = new TiledTextPart
            {
                ItemId    = Guid.NewGuid().ToString(),
                CreatorId = "zeus",
                UserId    = "zeus"
            };
            char c = 'a';

            for (int y = 0; y < rowCount; y++)
            {
                TextTileRow row = new TextTileRow
                {
                    Y = y + 1
                };
                part.Rows.Add(row);

                for (int x = 0; x < 3; x++)
                {
                    TextTile tile = new TextTile
                    {
                        X = x + 1,
                    };
                    tile.Data[TextTileRow.TEXT_DATA_NAME] = $"{c}{x + 1}";
                    row.Tiles.Add(tile);
                    if (++c > 'z')
                    {
                        c = 'a';
                    }
                }
            }
            return(part);
        }
        private void AddTiles(IEnumerable <XElement> wElements, TextTileRow row)
        {
            int x = 1;

            foreach (XElement w in wElements)
            {
                TextTile tile = new TextTile
                {
                    X = x++
                };
                // w's attributes
                foreach (XAttribute attr in w.Attributes())
                {
                    string key = GetKeyFromAttrName(attr.Name);
                    tile.Data[key] = attr.Value;
                }
                var textAndPatch = GetTextAndPatch(w.Value);
                if (textAndPatch != null)
                {
                    tile.Data["text"]  = textAndPatch.Item1;
                    tile.Data["patch"] = textAndPatch.Item2;
                }
                else
                {
                    tile.Data["text"] = w.Value;
                }
                row.Tiles.Add(tile);
            }
        }
Exemple #4
0
        object Old(TerrainTypes terrainTypes, TerrainMap map)
        {
            var desert  = new TextTile("Desert", '.', ConsoleColor.DarkYellow);
            var tileSet = new Dictionary <TerrainType, TextTile>
            {
                { terrainTypes.Grasland, new TextTile("Gras", 'g', ConsoleColor.DarkGreen) },
                { terrainTypes.Desert, desert },
                { terrainTypes.Hills, new TextTile("Hills", 'h', ConsoleColor.Gray) },
                { terrainTypes.Plains, new TextTile("Plains", '_', ConsoleColor.Green) }
            };

            bool Mapper(TerrainType key, out TextTile result, out Nothing context)
            {
                context = Nothing.Instance;
                return(tileSet.TryGetValue(key, out result));
            }

            return(new DirectMappingTileMatcher <TerrainType, TextTile, Nothing>(new TerrainLayer(map, terrainTypes).Read, Mapper));
        }
Exemple #5
0
        /// <summary>
        /// Creates and seeds a new part.
        /// </summary>
        /// <param name="item">The item this part should belong to.</param>
        /// <param name="roleId">The optional part role ID.</param>
        /// <param name="factory">The part seeder factory. This is used
        /// for layer parts, which need to seed a set of fragments.</param>
        /// <returns>A new part.</returns>
        /// <exception cref="ArgumentNullException">item or factory</exception>
        public override IPart GetPart(IItem item, string roleId,
                                      PartSeederFactory factory)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            TiledTextPart part = new TiledTextPart();

            SetPartMetadata(part, roleId, item);

            // citation
            part.Citation = Randomizer.Seed.Next(1, 100)
                            .ToString(CultureInfo.InvariantCulture);

            // from 2 to 10 rows
            var    faker = new Faker();
            string text  = faker.Lorem.Sentences(
                Randomizer.Seed.Next(2, 11));
            int y = 1;

            foreach (string line in text.Split('\n'))
            {
                // row
                TextTileRow row = new TextTileRow
                {
                    Y = y++,
                };
                // row's data
                for (int i = 0; i < Randomizer.Seed.Next(0, 4); i++)
                {
                    row.Data[$"d{(char)(i + 97)}"] = faker.Lorem.Word();
                }

                // add tiles in row
                int x = 1;
                foreach (string token in line.Trim().Split(' '))
                {
                    TextTile tile = new TextTile
                    {
                        X = x++,
                    };
                    // text
                    tile.Data[TextTileRow.TEXT_DATA_NAME] = token;
                    // other data
                    for (int i = 0; i < Randomizer.Seed.Next(0, 11); i++)
                    {
                        tile.Data[$"d{(char)(i + 97)}"] = faker.Lorem.Word();
                    }
                    row.Tiles.Add(tile);
                }

                part.Rows.Add(row);
            }

            return(part);
        }
 private static string GetTileText(TextTile tile) =>
 tile.Data.ContainsKey(TextTileRow.TEXT_DATA_NAME)
         ? tile.Data[TextTileRow.TEXT_DATA_NAME]
         : "";
Exemple #7
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            var terrainTypes = new TerrainTypes();
            var map          = TerrainMap.CreateMap(terrainTypes);

            var renderType = RenderType.Grid;
            var navigator  = new LimitedRangeNavigator <GridDirection>(GridNavigation.CreateNavigator(renderType), map.Width, map.Height);

            var desert       = new TextTile("Desert", '.', ConsoleColor.DarkYellow);
            var tileRegistry = new BasicTileRegistry <TextTile>()
            {
                { "terrain.grasland", new TextTile("Gras", 'g', ConsoleColor.DarkGreen) },
                { "terrain.desert", desert },
                { "terrain.hills", new TextTile("Hills", 'h', ConsoleColor.Gray) },
                { "terrain.plains", new TextTile("Plains", '_', ConsoleColor.Green) }
            };

            var list = new List <ITileMatcher <TextTile, Nothing> >
            {
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Desert,
                    navigator,
                    tileRegistry,
                    "terrain.desert"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Grasland,
                    navigator,
                    tileRegistry,
                    "terrain.grasland"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Hills,
                    navigator,
                    tileRegistry,
                    "terrain.hills"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Plains,
                    navigator,
                    tileRegistry,
                    "terrain.plains")
            };

            var bMatcher = new AggregateTileMatcher <TextTile, Nothing>(list);

            var viewport = new MapViewport(renderType)
            {
                SizeInTiles = new IntDimension(20, 20),
                CenterPoint = new ContinuousViewportCoordinates(0, 0)
            };

            var consoleRenderer = new ViewportRenderer <TextTile, Nothing>(viewport)
            {
                RenderTarget = new ConsoleRenderer()
            };
            var plotOp = new PlotOperation <TextTile, Nothing>(bMatcher, renderType, consoleRenderer);
            var t      = new GridPlotter(viewport, navigator);

            do
            {
                t.Draw(plotOp);
                var consoleKeyInfo = Console.ReadKey(true);
                if (consoleKeyInfo.Key == ConsoleKey.Escape || consoleKeyInfo.Key == ConsoleKey.Enter)
                {
                    break;
                }

                var center = viewport.CenterPoint;
                if (consoleKeyInfo.Key == ConsoleKey.LeftArrow)
                {
                    center += new ContinuousViewportCoordinates(-1, 0);
                }

                if (consoleKeyInfo.Key == ConsoleKey.RightArrow)
                {
                    center += new ContinuousViewportCoordinates(+1, 0);
                }

                if (consoleKeyInfo.Key == ConsoleKey.UpArrow)
                {
                    center += new ContinuousViewportCoordinates(0, -1);
                }

                if (consoleKeyInfo.Key == ConsoleKey.DownArrow)
                {
                    center += new ContinuousViewportCoordinates(0, +1);
                }

                viewport.CenterPoint = center;
            } while (true);
        }