Beispiel #1
0
        private static void Main()
        {
            const int MapWidth  = 20;
            const int MapHeight = 20;
            Dictionary <TileValues, int> tileValuesAndOccuranceChance = new Dictionary <TileValues, int>
            {
                { TileValues.Fortress, 5 },
                { TileValues.City, 20 },
                { TileValues.Village, 100 },
                { TileValues.Forest, 1000 },
                { TileValues.Grassland, 2500 },
            };

            Dictionary <CreatureTypes, int> creatureTypeAndTotalAmountGenerated = new Dictionary <CreatureTypes, int>()
            {
                { CreatureTypes.Human, 100 },
                { CreatureTypes.Goblin, 200 },
                { CreatureTypes.Troll, 50 },
            };

            MapCreator creator = new MapCreator();
            IMap       map     = creator.GenerateFlatMap(MapWidth, MapHeight, tileValuesAndOccuranceChance);

            MapDrawer.DrawMap(map);

            creator.GenerateMapElements(map);
            creator.AddCreaturesToMap(map, creatureTypeAndTotalAmountGenerated);
            MapDrawer.DrawMapTileShopsAndNpcs(map);

            Console.WriteLine("Hello World!");
        }
Beispiel #2
0
        private void SetupTest()
        {
            time = new Time();
            MapCreator creator = new MapCreator();

            map = creator.GenerateFlatMap(MapWidth, MapHeight, tileValueAndAppearanceChance);
            creator.GenerateMapElements(map);
            creator.AddCreaturesToMap(map, creatureTypeAndAppearanceChance);
        }
Beispiel #3
0
        public void AddCreaturesToMapTest()
        {
            const int MapWidth  = 10;
            const int MapHeight = 10;

            IDictionary <TileValues, int> tileValueAndAppearanceChance = new Dictionary <TileValues, int>()
            {
                { TileValues.Grassland, 10 },
                { TileValues.Forest, 10 },
                { TileValues.Village, 10 },
                { TileValues.City, 10 },
                { TileValues.Fortress, 10 },
            };

            IDictionary <CreatureTypes, int> creatureTypeAndTotalAmountGenerated = new Dictionary <CreatureTypes, int>()
            {
                { CreatureTypes.Human, 100 },
                { CreatureTypes.Goblin, 200 },
                { CreatureTypes.Troll, 50 },
            };

            IMapCreator creator = new MapCreator();
            IMap        map     = creator.GenerateFlatMap(MapWidth, MapHeight, tileValueAndAppearanceChance);

            creator.GenerateMapElements(map);
            creator.AddCreaturesToMap(map, creatureTypeAndTotalAmountGenerated);

            ITile[] creatureTiles = map.Tiles
                                    .Where(x
                                           => x.CreatureList.Count > 0)
                                    .ToArray();

            foreach (KeyValuePair <CreatureTypes, int> creatureTypeAndGenerated in creatureTypeAndTotalAmountGenerated)
            {
                IList <IList <ICreature> > creaturesListLists = creatureTiles.Select(x => x.CreatureList).ToList();
                int creatureCount = 0;
                foreach (IList <ICreature> creatureList in creaturesListLists)
                {
                    foreach (ICreature creature in creatureList)
                    {
                        if (creature.CreatureType == creatureTypeAndGenerated.Key)
                        {
                            ++creatureCount;
                        }
                    }
                }

                Assert.AreEqual(creatureTypeAndGenerated.Value, creatureCount);
            }

            foreach (ITile tile in creatureTiles)
            {
                switch (tile.TileValue)
                {
                case TileValues.Village:
                case TileValues.City:
                case TileValues.Fortress:
                    int totalAccepptedCreatures = tile.CreatureList.Count(x     // Count total Human-Creatures
                                                                          => x.CreatureType == CreatureTypes.Human);
                    Assert.AreEqual(totalAccepptedCreatures, tile.CreatureList.Count);
                    break;

                case TileValues.Forest:
                case TileValues.Grassland:
                    int totalNotAcceptedCreatures = tile.CreatureList.Count(x     // Count total Not-Human-Creatures
                                                                            => x.CreatureType != CreatureTypes.Human);
                    Assert.AreEqual(totalNotAcceptedCreatures, tile.CreatureList.Count);
                    break;

                default:
                    throw new System.Exception("Unchecked Tile-Value");
                }
            }
        }