Exemple #1
0
        private void PlaceEntities(Rectangle room, List <Entity> entities)
        {
            var maxMonstersPerRoom = FromDungeonLevel(new Dictionary <int, int> {
                { 1, 2 }, { 4, 3 }, { 6, 5 }
            });
            var maxItemsPerRoom = FromDungeonLevel(new Dictionary <int, int> {
                { 1, 1 }, { 4, 2 }
            });
            var numMonsters = Rng.Next(maxMonstersPerRoom + 1);
            var numItems    = Rng.Next(maxItemsPerRoom + 1);

            var monsterChances = new Dictionary <string, int>
            {
                { Monsters.Orc, 80 }, { Monsters.Troll, FromDungeonLevel(new Dictionary <int, int> {
                        { 3, 15 }, { 5, 30 }, { 7, 60 }
                    }) }
            };
            var itemChances = new Dictionary <string, int>
            {
                { Items.HealingPotion, 35 },
                { Items.LightningScroll, FromDungeonLevel(new Dictionary <int, int> {
                        { 4, 25 }
                    }) },
                { Items.FireballScroll, FromDungeonLevel(new Dictionary <int, int> {
                        { 6, 25 }
                    }) },
                { Items.ConfusionScroll, FromDungeonLevel(new Dictionary <int, int> {
                        { 2, 10 }
                    }) },
                { Items.Sword, FromDungeonLevel(new Dictionary <int, int> {
                        { 4, 5 }
                    }) },
                { Items.Shield, FromDungeonLevel(new Dictionary <int, int> {
                        { 8, 15 }
                    }) }
            };

            for (int i = 0; i < numMonsters; i++)
            {
                var x = Rng.Next(room.X1 + 1, room.X2);
                var y = Rng.Next(room.Y1 + 1, room.Y2);

                if (!entities.Any(entity => entity.X == x && entity.Y == y))
                {
                    var monster = Monsters.Get(Rng.ChoiceFromDictionary(monsterChances), x, y);
                    entities.Add(monster);
                }
            }

            for (int i = 0; i < numItems; i++)
            {
                var x = Rng.Next(room.X1 + 1, room.X2 - 1);
                var y = Rng.Next(room.Y1 + 1, room.Y2 - 1);

                if (!entities.Any(entity => entity.X == x && entity.Y == y))
                {
                    var item = Items.Get(Rng.ChoiceFromDictionary(itemChances), x, y);
                    entities.Add(item);
                }
            }
        }