Beispiel #1
0
        /// <summary>
        /// Generates a complete level, as a two-dimensional array
        /// </summary>
        /// <param name="edgeSize">Max size of the edges of the level. Set -1 to have size determined by difficulty</param>
        /// <param name="difficulty">Used in generating enemies and size of the level (if edgeSize was -1). 1 is easiest</param>
        /// <returns>A two-dimensional array of Room objects</returns>
        /// <exception cref="Exception">When trying to generate a level with edge size smaller than 3</exception>
        public Room[,] GenerateLevel(int edgeSize, int difficulty)
        {
            // Setup
            if (edgeSize == -1)
            {
                _edgeSize = 3 + difficulty * 2;
            }
            else if (edgeSize < 3)
            {
                throw new Exception("Cannot generate level smaller than 3x3");
            }
            else
            {
                _edgeSize = edgeSize;
            }

            _difficulty = difficulty;
            _hasEnd     = false;
            _level      = new Room[_edgeSize, _edgeSize];

            // Choose starting place
            int x = _random.Next(1, _edgeSize - 1);
            int z = _random.Next(1, _edgeSize - 1);

            _level[x, z] = new FourWayRoom(x, z, 0)
            {
                Beginning = true
            };

            // Starting the recursive generation
            ContinueFrom(_level[x, z]);

            // Generation finished, return room
            return(_level);
        }
Beispiel #2
0
        public void FourWayRoomWorks()
        {
            var room = new FourWayRoom(11, 9, 3);

            Assert.True(room.HasDoorwayTo(0));
            Assert.True(room.HasDoorwayTo(1));
            Assert.True(room.HasDoorwayTo(2));
            Assert.True(room.HasDoorwayTo(3));
        }