Пример #1
0
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        void CheckLocation(CsRogueMap csRogueMap, int iCol, int iRow, TerrainType terrain, ItemType itemType = ItemType.Nothing)
        {
            if (itemType != ItemType.Nothing)
            {
                Assert.AreEqual(1, csRogueMap.Items(iCol, iRow).Count);
                Assert.AreEqual(itemType, csRogueMap.Items(iCol, iRow)[0].ItemType);
            }
            else
            {
                Assert.AreEqual(0, csRogueMap.Items(iCol, iRow).Count);
            }
            Assert.AreEqual(terrain, csRogueMap.Terrain(iCol, iRow));
        }
Пример #2
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        public FOV Test(string mapString, MapCoordinates location, int maxRow, int countSeen)
        {
            MemoryStream  stream     = new MemoryStream(Encoding.Default.GetBytes(mapString));
            FileExcavator excavator  = new FileExcavator(stream);
            CsRogueMap    csRogueMap = new CsRogueMap();

            excavator.Excavate(csRogueMap);

            FOV fov = new FOV(csRogueMap, maxRow);

            fov.Scan(location);
            Assert.AreEqual(countSeen, fov.NewlySeen.ToList().Count);
            return(fov);
        }
Пример #3
0
        public void MapConstructorTest()
        {
            CsRogueMap target = new CsRogueMap();

            for (int iCol = 0; iCol < target.Width; iCol++)
            {
                for (int iRow = 0; iRow < target.Height; iRow++)
                {
                    MapLocationData data = target[iCol, iRow];
                    Assert.AreEqual(0, data.Items.Count);
                    Assert.AreEqual(TerrainType.OffMap, data.Terrain);
                }
            }
        }
Пример #4
0
        public void ExcavateByGridTest()
        {
            CsRogueMap    map1      = new CsRogueMap();
            GridExcavator excavator = new GridExcavator(seed: 0);

            excavator.Excavate(map1);
            string     str1 = map1.ToString();
            CsRogueMap map2 = new CsRogueMap();

            excavator.Excavate(map2);
            string str2 = map2.ToString();

            Assert.AreEqual(str1, str2);
        }
Пример #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Generates a map. </summary>
        ///
        /// <remarks>   Darrellp, 8/26/2016. </remarks>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void GenerateMap()
        {
            _csRogueMap = new CsRogueMap(Width, Height);
            var excavator = new GridExcavator();

            excavator.Excavate(_csRogueMap);
            // Create the local cache of map data
            //
            _mapData = new MapObject[Width, Height];

            // Loop through the map information generated by RogueSharp and create our cached visuals of that data
            for (var iCol = 0; iCol < Width; iCol++)
            {
                for (var iRow = 0; iRow < Height; iRow++)
                {
                    var terrain = _csRogueMap[iCol, iRow].Terrain;
                    if (terrain == TerrainType.OffMap)
                    {
                        continue;
                    }
                    string str = MapTerrainToAppearance[_csRogueMap[iCol, iRow].Terrain];
                    var    obj = _mapData[iCol, iRow] = new MapObject(MapObjectFactory.ObjectNameToAppearance[str]);
                    obj.Appearance.CopyAppearanceTo(this[iCol, iRow]);
                    obj.RemoveCellFromView(this[iCol, iRow]);
                }
            }

            Player.Position = _csRogueMap.RandomFloorLocation().ToPoint();

            // Center the veiw area
            TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2),
                                                   Player.Position.Y - (TextSurface.RenderArea.Height / 2),
                                                   TextSurface.RenderArea.Width, TextSurface.RenderArea.Height);

            Player.RenderOffset = Position - TextSurface.RenderArea.Location;
            _fov = new FOV(_csRogueMap, FovDistance);
            _fov.Scan(Player.Position.ToMapCoordinates());
            foreach (var loc in _fov.CurrentlySeen)
            {
                _mapData[loc.Column, loc.Row].RenderToCell(this[loc.Column, loc.Row], true, true);
            }
        }
Пример #6
0
        public void ExcavateTest()
        {
            const string mapString =
                @"@r-............
...............
...............
...............";
            MemoryStream  stream     = new MemoryStream(Encoding.Default.GetBytes(mapString));
            FileExcavator excavator  = new FileExcavator(stream);
            CsRogueMap    csRogueMap = new CsRogueMap();

            excavator.Excavate(csRogueMap);
            CheckLocation(csRogueMap, 0, 0, TerrainType.Floor, ItemType.Player);
            CheckLocation(csRogueMap, 1, 0, TerrainType.Floor, ItemType.Rat);
            CheckLocation(csRogueMap, 2, 0, TerrainType.HorizontalWall);
            CheckLocation(csRogueMap, 3, 0, TerrainType.Floor);
            CheckLocation(csRogueMap, 14, 0, TerrainType.Floor);
            CheckLocation(csRogueMap, 15, 0, TerrainType.OffMap);
            CheckLocation(csRogueMap, 14, 3, TerrainType.Floor);
            CheckLocation(csRogueMap, 15, 4, TerrainType.OffMap);
        }