本文整理汇总了C#中IMap.GetAllCells方法的典型用法代码示例。如果您正苦于以下问题:C# IMap.GetAllCells方法的具体用法?C# IMap.GetAllCells怎么用?C# IMap.GetAllCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMap
的用法示例。
在下文中一共展示了IMap.GetAllCells方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PathFinder
/// <summary>
/// Constructs a new PathFinder instance for the specified Map
/// </summary>
/// <param name="map">The Map that this PathFinder instance will run shortest path algorithms on</param>
/// <exception cref="ArgumentNullException">Thrown on null map</exception>
public PathFinder( IMap map )
{
if ( map == null )
{
throw new ArgumentNullException( "map", "Map cannot be null" );
}
_map = map;
_graph = new EdgeWeightedDigraph( _map.Width * _map.Height );
foreach ( Cell cell in _map.GetAllCells() )
{
if ( cell.IsWalkable )
{
int v = IndexFor( cell );
foreach ( Cell neighbor in _map.GetBorderCellsInRadius( cell.X, cell.Y, 1 ) )
{
if ( neighbor.IsWalkable )
{
int w = IndexFor( neighbor );
_graph.AddEdge( new DirectedEdge( v, w, 1.0 ) );
_graph.AddEdge( new DirectedEdge( w, v, 1.0 ) );
}
}
}
}
}
示例2: MapConsole
public MapConsole(int width, int height)
: base(width, height)
{
// Create the map
IMapCreationStrategy<Map> mapCreationStrategy = new RandomRoomsMapCreationStrategy<Map>(width, height, 100, 15, 4);
map = Map.Create(mapCreationStrategy);
mapData = new SadConsole.CellAppearance[width, height];
foreach (var cell in map.GetAllCells())
{
if (cell.IsWalkable)
{
// Our local information about each map square
mapData[cell.X, cell.Y] = new MapObjects.Floor();
// Copy the appearance we've defined for Floor or Wall or whatever, to the actual console data that is rendered
mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]);
}
else
{
mapData[cell.X, cell.Y] = new MapObjects.Wall();
mapData[cell.X, cell.Y].CopyAppearanceTo(this[cell.X, cell.Y]);
}
}
// Create map effects
explored = new SadConsole.Effects.Recolor();
explored.Background = Color.White * 0.3f;
explored.Foreground = Color.White * 0.3f;
explored.Update(10d); // Trickery to force the fade to complete to the destination color.
// Entities
entities = new List<SadConsole.Game.GameObject>();
// Create the player
player = new Entities.Player();
var tempCell = GetRandomEmptyCell();
player.Position = new Microsoft.Xna.Framework.Point(tempCell.X, tempCell.Y);
player.RenderOffset = this.Position;
entities.Add(player);
// Create a hound
GenerateHound();
GenerateHound();
GenerateHound();
// Initial view
UpdatePlayerView();
// Keyboard setup
SadConsole.Engine.Keyboard.RepeatDelay = 0.07f;
SadConsole.Engine.Keyboard.InitialRepeatDelay = 0.1f;
}
示例3: Copy
public void Copy( IMap sourceMap, int left = 0, int top = 0 )
{
if ( sourceMap.Width + left > Width )
{
throw new ArgumentException( "Source map 'width' + 'left' cannot be larger than the destination map width", "destinationMap" );
}
if ( sourceMap.Height + top > Height )
{
throw new ArgumentException( "Source map 'height' + 'top' cannot be larger than the destination map height", "destinationMap" );
}
if ( sourceMap is LibtcodMap && left == 0 && top == 0 )
{
LibtcodMap mapToCopyFrom = sourceMap as LibtcodMap;
TCODMap.copy( mapToCopyFrom.TCODMap );
}
else
{
foreach ( Cell cell in sourceMap.GetAllCells() )
{
SetCellProperties( cell.X + left, cell.Y + top, cell.IsTransparent, cell.IsWalkable );
}
}
}
示例4: Copy
/// <summary>
/// Copies the Cell properties of a smaller source Map into this destination Map at the specified location
/// </summary>
/// <param name="sourceMap">An IMap which must be of smaller size and able to fit in this destination Map at the specified location</param>
/// <param name="left">Optional parameter defaults to 0 if not provided. X location of the Cell to start copying parameters to, starting with 0 as the farthest left</param>
/// <param name="top">Optional parameter defaults to 0 if not provided. Y location of the Cell to start copying parameters to, starting with 0 as the top</param>
/// <exception cref="ArgumentNullException">Thrown on null source map</exception>
/// <exception cref="ArgumentException">Thrown on invalid source map dimensions</exception>
public void Copy( IMap sourceMap, int left, int top )
{
if ( sourceMap == null )
{
throw new ArgumentNullException( "sourceMap", "Source map cannot be null" );
}
if ( sourceMap.Width + left > Width )
{
throw new ArgumentException( "Source map 'width' + 'left' cannot be larger than the destination map width" );
}
if ( sourceMap.Height + top > Height )
{
throw new ArgumentException( "Source map 'height' + 'top' cannot be larger than the destination map height" );
}
foreach ( Cell cell in sourceMap.GetAllCells() )
{
SetCellProperties( cell.X + left, cell.Y + top, cell.IsTransparent, cell.IsWalkable, cell.IsExplored );
}
}