Пример #1
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);
        }
Пример #2
0
 /// <summary>
 /// Get a MapState POCO which represents this Map and can be easily serialized
 /// Use Restore with the MapState to get back a full Map
 /// </summary>
 /// <returns>Mapstate POCO (Plain Old C# Object) which represents this Map and can be easily serialized</returns>
 public MapState Save()
 {
     var mapState = new MapState();
      mapState.Width = Width;
      mapState.Height = Height;
      mapState.Cells = new MapState.CellProperties[Width * Height];
      foreach ( Cell cell in GetAllCells() )
      {
     var cellProperties = MapState.CellProperties.None;
     if ( cell.IsInFov )
     {
        cellProperties |= MapState.CellProperties.Visible;
     }
     if ( cell.IsTransparent )
     {
        cellProperties |= MapState.CellProperties.Transparent;
     }
     if ( cell.IsWalkable )
     {
        cellProperties |= MapState.CellProperties.Walkable;
     }
     mapState.Cells[cell.Y * Width + cell.X] = cellProperties;
      }
      return mapState;
 }
Пример #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 );
        }