Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Move player by a delta. </summary>
        ///
        /// <remarks>   Darrellp, 8/26/2016. </remarks>
        ///
        /// <param name="amount">   The delta to move the player by. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void MovePlayerBy(Point amount)
        {
            // Get the position the player will be at
            var newPosition = Player.Position + amount;
            var terrain     = _csRogueMap[newPosition.X, newPosition.Y].Terrain;

            // Check to see if the position is within the map
            if (new Rectangle(0, 0, Width, Height).Contains(newPosition) && terrain != TerrainType.Wall)
            {
                // Move the player
                Player.Position            += amount;
                _csRogueMap.Player.Location = Player.Position.ToMapCoordinates();

                // Scroll the view area to center the player on the screen
                TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2),
                                                       Player.Position.Y - (TextSurface.RenderArea.Height / 2),
                                                       TextSurface.RenderArea.Width, TextSurface.RenderArea.Height);

                // If he view area moved, we'll keep our entity in sync with it.
                Player.RenderOffset = Position - TextSurface.RenderArea.Location;

                _fov.Scan(Player.Position.ToMapCoordinates());
                foreach (var loc in _fov.NewlySeen)
                {
                    _mapData[loc.Column, loc.Row].RenderToCell(
                        this[loc.Column, loc.Row],
                        true,
                        _csRogueMap[loc.Column, loc.Row].LitState == LitState.Remembered);
                }
                foreach (var loc in _fov.NewlyUnseen)
                {
                    _mapData[loc.Column, loc.Row].RenderToCell(
                        this[loc.Column, loc.Row],
                        false,
                        _csRogueMap[loc.Column, loc.Row].LitState == LitState.Remembered);
                }
            }
        }