Пример #1
0
 /// <summary>
 /// Create a new map with the properties of all Cells set to false
 /// </summary>
 /// <remarks>
 /// This is basically a solid stone map that would then need to be modified to have interesting features
 /// </remarks>
 /// <param name="width">How many Cells wide the Map will be</param>
 /// <param name="height">How many Cells tall the Map will be</param>
 public void Initialize(int width, int height)
 {
     Width          = width;
     Height         = height;
     _isTransparent = new bool[width, height];
     _isWalkable    = new bool[width, height];
     _isExplored    = new bool[width, height];
     _fieldOfView   = new FieldOfView(this);
 }
Пример #2
0
        /// <summary>
        /// Restore the state of this Map from the specified MapState
        /// </summary>
        /// <param name="state">Mapstate POCO (Plain Old C# Object) which represents this Map and can be easily serialized and deserialized</param>
        /// <exception cref="ArgumentNullException">Thrown on null map state</exception>
        public void Restore(MapState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state", "Map state cannot be null");
            }

            var inFov = new HashSet <int>();

            Initialize(state.Width, state.Height);
            foreach (ICell cell in GetAllCells())
            {
                MapState.CellProperties cellProperties = state.Cells[cell.Y * Width + cell.X];
                if (cellProperties.HasFlag(MapState.CellProperties.Visible))
                {
                    inFov.Add(IndexFor(cell.X, cell.Y));
                }
                _isTransparent[cell.X, cell.Y] = cellProperties.HasFlag(MapState.CellProperties.Transparent);
                _isWalkable[cell.X, cell.Y]    = cellProperties.HasFlag(MapState.CellProperties.Walkable);
            }

            _fieldOfView = new FieldOfView(this, inFov);
        }
Пример #3
0
        /// <summary>
        /// Restore the state of this Map from the specified MapState
        /// </summary>
        /// <param name="state">Mapstate POCO (Plain Old C# Object) which represents this Map and can be easily serialized and deserialized</param>
        /// <exception cref="ArgumentNullException">Thrown on null map state</exception>
        public void Restore( MapState state )
        {
            if ( state == null )
             {
            throw new ArgumentNullException( "state", "Map state cannot be null" );
             }

             var inFov = new HashSet<int>();

             Initialize( state.Width, state.Height );
             foreach ( Cell cell in GetAllCells() )
             {
            MapState.CellProperties cellProperties = state.Cells[cell.Y * Width + cell.X];
            if ( cellProperties.HasFlag( MapState.CellProperties.Visible ) )
            {
               inFov.Add( IndexFor( cell.X, cell.Y ) );
            }
            _isTransparent[cell.X, cell.Y] = cellProperties.HasFlag( MapState.CellProperties.Transparent );
            _isWalkable[cell.X, cell.Y] = cellProperties.HasFlag( MapState.CellProperties.Walkable );
             }

             _fieldOfView = new FieldOfView( this, inFov );
        }
Пример #4
0
 /// <summary>
 /// Create a new map with the properties of all Cells set to false
 /// </summary>
 /// <remarks>
 /// This is basically a solid stone map that would then need to be modified to have interesting features
 /// </remarks>
 /// <param name="width">How many Cells wide the Map will be</param>
 /// <param name="height">How many Cells tall the Map will be</param>
 public void Initialize( int width, int height )
 {
     Width = width;
      Height = height;
      _isTransparent = new bool[width, height];
      _isWalkable = new bool[width, height];
      _isExplored = new bool[width, height];
      _fieldOfView = new FieldOfView( this );
 }