Example #1
0
        // Method to place monsters on the map.
        private void PlaceMonsters()
        {
            foreach (var room in _map.Rooms)
            {
                // Each room has a 60% chance of having monsters
                if (Dice.Roll("1D10") < 7)
                {
                    // Generate between 1 and 4 monsters
                    var numberOfMonsters = Dice.Roll("1D4");

                    for (int i = 0; i < numberOfMonsters; i++)
                    {
                        if (_map.DoesRoomHaveWalkableSpace(room))
                        {
                            // Find a random walkable location in the room to place the monster
                            Point randomRoomLocation = _map.GetRandomLocationInRoom(room);

                            // It's possible that the room doesn't have space to place a monster
                            // In that case skip creating the monster
                            if (randomRoomLocation != null)
                            {
                                _map.AddMonster(ActorGenerator.CreateMonster(_level, _map.GetRandomLocationInRoom(room)));
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        // Find the center of the first room that we created and place the Player there
        private void PlacePlayer()
        {
            Player player = ActorGenerator.CreatePlayer();

            player.X = _map.Rooms[0].Center.X;
            player.Y = _map.Rooms[0].Center.Y;

            _map.AddPlayer(player);
        }