예제 #1
0
        public void AppendFov_SmallMap_ExpectedCollectionOfVisibleCells()
        {
            string mapRepresentation = @"####################################
                                      #..................................#
                                      #..###.########....................#
                                      #....#.#......#....................#
                                      #....#.#......#....................#
                                      #.............#....................#
                                      #....#.#......######################
                                      #....#.#...........................#
                                      #....#.#...........................#
                                      #..................................#
                                      ####################################";
            IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation);
            IMap map = Map.Create(mapCreationStrategy);

            var fieldOfView = new FieldOfView(map);

            fieldOfView.ComputeFov(6, 1, 20, true);
            var visibleCells = fieldOfView.AppendFov(15, 1, 5, true);

            // The field of view should be calculated as follows
            //
            //  ###########################%%%%%%%%%
            //  #..........................%%%%%%%%%
            //  #..###.########...........%%%%%%%%%%
            //  #%%%%#.#%%%%%%#....%%%%%%%%%%%%%%%%%
            //  %%%%%#.#%%%%%%#...%%%%%%%%%%%%%%%%%%
            //  %%%%%%.%%%%%%%#..%%%%%%%%%%%%%%%%%%%
            //  %%%%%#.#%%%%%%####%%%%%%%%%%%%%%%%%%
            //  %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            //  %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            //  %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            //  %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            int floorCells = 0;
            int wallCells  = 0;

            foreach (ICell cell in visibleCells)
            {
                if (cell.IsWalkable)
                {
                    floorCells++;
                }
                else
                {
                    wallCells++;
                }
            }

            Assert.AreEqual(117, visibleCells.Count);
            Assert.AreEqual(56, floorCells);
            Assert.AreEqual(61, wallCells);
        }
예제 #2
0
 /// <summary>
 /// Performs a field-of-view calculation with the specified parameters and appends it any existing field-of-view calculations.
 /// Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Block with a given light radius.
 /// </summary>
 /// <example>
 /// When a character is holding a light source in a large area that also has several other sources of light such as torches along the walls
 /// ComputeFov could first be called for the character and then AppendFov could be called for each torch to give us the final combined FOV given all the light sources
 /// </example>
 /// <param name="xOrigin">X location of the Block to perform the field-of-view calculation with 0 as the farthest left</param>
 /// <param name="yOrigin">Y location of the Block to perform the field-of-view calculation with 0 as the top</param>
 /// <param name="radius">The number of Blocks in which the field-of-view extends from the origin Block. Think of this as the intensity of the light source.</param>
 /// <param name="lightWalls">True if walls should be included in the field-of-view when they are within the radius of the light source. False excludes walls even when they are within range.</param>
 /// <returns>List of Blocks representing what is observable in the Map based on the specified parameters</returns>
 public ReadOnlyCollection <IBlock> AppendFoV(int xOrigin, int yOrigin, int radius, bool lightWalls)
 {
     return(_fieldOfView.AppendFov(xOrigin, yOrigin, radius, lightWalls));
 }