本文整理汇总了C#中Map.SetTerrainAt方法的典型用法代码示例。如果您正苦于以下问题:C# Map.SetTerrainAt方法的具体用法?C# Map.SetTerrainAt怎么用?C# Map.SetTerrainAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.SetTerrainAt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnplaceChunkOnMapAtPosition
internal void UnplaceChunkOnMapAtPosition(Map map, Point upperLeftCorner)
{
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
Point mapPosition = upperLeftCorner + new Point(i, j);
map.SetTerrainAt(mapPosition, TerrainType.Wall);
}
}
Point lowerRight = upperLeftCorner + new Point(Width, Height);
foreach (Monster m in map.Monsters.OfType<Monster>().Where(x => x.Position.IsInRange(upperLeftCorner, lowerRight)).ToList())
{
map.RemoveMonster(m);
}
foreach (Point treasurePosition in TreasureChests)
{
MapObject objectAtPoint = (MapObject)map.MapObjects.SingleOrDefault(x => x.Position == (upperLeftCorner + treasurePosition));
if (objectAtPoint != null)
map.RemoveMapItem(objectAtPoint);
}
foreach (Point doorPosition in Doors)
{
MapObject objectAtPoint = (MapObject)map.MapObjects.SingleOrDefault(x => x.Position == (upperLeftCorner + doorPosition));
if (objectAtPoint != null)
map.RemoveMapItem(objectAtPoint);
}
foreach (Point cosmeticPosition in Cosmetics)
{
MapObject objectAtPoint = (MapObject)map.MapObjects.SingleOrDefault(x => x.Position == (upperLeftCorner + cosmeticPosition));
if (objectAtPoint != null)
map.RemoveMapItem(objectAtPoint);
}
}
示例2: FillEdgesWithWalls
protected void FillEdgesWithWalls(Map map)
{
// Fill edges with walls
for (int i = 0; i < map.Width; ++i)
{
map.SetTerrainAt(i, 0, TerrainType.Wall);
map.SetTerrainAt(i, map.Height - 1, TerrainType.Wall);
}
for (int j = 0; j < map.Height; ++j)
{
map.SetTerrainAt(0, j, TerrainType.Wall);
map.SetTerrainAt(map.Width - 1, j, TerrainType.Wall);
}
}
示例3: PlaceChunkOnMapAtPosition
internal void PlaceChunkOnMapAtPosition(Map map, Point upperLeftCorner, Random random)
{
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
Point mapPosition = upperLeftCorner + new Point(i, j);
map.SetTerrainAt(mapPosition, MapSegment[i, j].Terrain);
}
}
MapObjectFactory mapItemFactory = MapObjectFactory.Instance;
TreasureChests.ForEach(treasurePosition => map.AddMapItem(mapItemFactory.CreateMapObject("TreasureChest", upperLeftCorner + treasurePosition)));
int chanceToPlaceDoor = this.Type == MapNodeType.TreasureRoom ? TreasureRoomChanceToPlaceDoorAtSpot : NormalChanceToPlaceDoorAtSpot;
Doors.Where(x => m_random.Chance(chanceToPlaceDoor)).ToList().ForEach(doorPosition => map.AddMapItem(mapItemFactory.CreateMapObject("MapDoor", upperLeftCorner + doorPosition)));
Cosmetics.ForEach(cosmeticPosition => map.AddMapItem(mapItemFactory.CreateMapObject("Cosmetic", upperLeftCorner + cosmeticPosition)));
}
示例4: FillAllSmallerUnconnectedRooms
protected void FillAllSmallerUnconnectedRooms(Map map)
{
int currentScratchNumber = FloodFillWithContigiousNumbers(map);
// Walk each tile, and count up the different groups.
int[] numberOfTilesWithThatScratch = new int[currentScratchNumber];
numberOfTilesWithThatScratch.Initialize();
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor)
numberOfTilesWithThatScratch[map.GetScratchAt(i, j)]++;
}
}
if (numberOfTilesWithThatScratch[0] != 0)
throw new MapGenerationFailureException("Some valid tiles didn't get a scratch during FillAllSmallerRooms.");
// Find the largest collection
int biggestNumber = 1;
for (int i = 2; i < currentScratchNumber; ++i)
{
if (numberOfTilesWithThatScratch[i] > numberOfTilesWithThatScratch[biggestNumber])
biggestNumber = i;
}
// Now walk level, and turn every floor tile without that scratch into a wall
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor && map.GetScratchAt(i, j) != biggestNumber)
map.SetTerrainAt(i, j, TerrainType.Wall);
// And reset the scratch while we're here
map.SetScratchAt(i, j, 0);
}
}
if (!CheckConnectivity(map))
throw new MapGenerationFailureException("FillAllSmallerUnconnectedRooms produced a non-connected map.");
}
示例5: PlaceMapNode
// Returns true if placed, false if we walled off seam
private bool PlaceMapNode(MapNode current, MapChunk mapChunk, Map map, Point seam, ParenthoodChain parentChain)
{
Point placedUpperLeftCorner = mapChunk.PlaceChunkOnMap(map, seam, m_level);
if (placedUpperLeftCorner == Point.Invalid)
{
map.SetTerrainAt(seam, TerrainType.Wall);
return false;
}
else
{
PossiblyUpdateLargestSmallestPoint(placedUpperLeftCorner, mapChunk);
map.SetTerrainAt(seam, TerrainType.Floor);
parentChain.Push(mapChunk, placedUpperLeftCorner, seam);
WalkNeighbors(current, mapChunk, map, placedUpperLeftCorner, parentChain);
parentChain.Pop();
return true;
}
}
示例6: UnplacePossibleHallwayToNowhere
private void UnplacePossibleHallwayToNowhere(Map map, ParenthoodChain parentChain)
{
ParenthoodChain localChain = new ParenthoodChain(parentChain);
ParenthoodElement top = localChain.Pop();
Point seamToFill = Point.Invalid;
if (top.Chunk.Type == MapNodeType.Hall)
{
do
{
if (top.Chunk.Type == MapNodeType.Hall)
{
m_placed--;
top.Chunk.UnplaceChunkOnMapAtPosition(map, top.UpperLeft);
seamToFill = top.Seam;
top = localChain.Pop();
}
else
{
if (seamToFill == Point.Invalid)
throw new MapGenerationFailureException("Trying to fill in invalid seam");
map.SetTerrainAt(seamToFill, TerrainType.Wall);
break;
}
}
while (true);
}
}
示例7: GenerateMapFromGraph
private void GenerateMapFromGraph(MapNode current, Map map, Point seam, ParenthoodChain parentChain)
{
if (current.Generated)
return;
current.Generated = true;
bool placed = false;
switch (current.Type)
{
case MapNodeType.Entrance:
{
placed = true;
MapChunk entranceChunk = GetRandomChunkFromList(m_entrances);
// We need to place entrace so it's at our expected location
Point randomCenter = new Point(m_random.getInt(100, 150), m_random.getInt(100, 150));
Point entraceUpperLeftCorner = randomCenter - entranceChunk.PlayerPosition;
parentChain.Push(entranceChunk, entraceUpperLeftCorner, Point.Invalid);
entranceChunk.PlaceChunkOnMapAtPosition(map, entraceUpperLeftCorner, m_random);
PossiblyUpdateLargestSmallestPoint(entraceUpperLeftCorner, entranceChunk);
map.AddMapItem(MapObjectFactory.Instance.CreateMapObject("StairsUp", entranceChunk.PlayerPosition + entraceUpperLeftCorner));
if (current.Neighbors.Count != entranceChunk.Seams.Count)
throw new InvalidOperationException("Number of neighbors should equal number of seams.");
WalkNeighbors(current, entranceChunk, map, entraceUpperLeftCorner, parentChain);
parentChain.Pop();
break;
}
case MapNodeType.Hall:
{
for (int i = 0; i < 10; i++)
{
placed = PlaceMapNode(current, GetRandomChunkFromList(m_halls), map, seam, parentChain);
if (placed)
break;
}
break;
}
case MapNodeType.None:
{
// If we have nothing, see if we have any orphan nodes to try to place
if (m_unplacedDueToSpace.Count > 0)
{
// Grab the first unplaced node, and try again.
MapNode treeToGraphOn = m_unplacedDueToSpace.Dequeue();
treeToGraphOn.Generated = false;
GenerateMapFromGraph(treeToGraphOn, map, seam, parentChain);
}
else
{
map.SetTerrainAt(seam, TerrainType.Wall);
if (current.Neighbors.Count != 0)
throw new InvalidOperationException("None Node types should only have no neighbors");
}
placed = true;
break;
}
case MapNodeType.MainRoom:
{
placed = PlaceMapNode(current, GetRandomChunkFromList(m_mainRooms), map, seam, parentChain);
break;
}
case MapNodeType.TreasureRoom:
{
placed = PlaceMapNode(current, GetRandomChunkFromList(m_treasureRooms), map, seam, parentChain);
break;
}
case MapNodeType.SideRoom:
{
placed = PlaceMapNode(current, GetRandomChunkFromList(m_sideRooms), map, seam, parentChain);
break;
}
case MapNodeType.NoneGivenYet:
default:
throw new InvalidOperationException("Trying to generate MapNode from invalid node.");
}
if (!placed)
{
UnplacePossibleHallwayToNowhere(map, parentChain);
m_unplacedDueToSpace.Enqueue(current);
}
}
示例8: GenerateMap
public override Map GenerateMap(Stairs incommingStairs, int level)
{
Map map;
int width = m_random.getInt(40, 60);
int height = m_random.getInt(40, 60);
map = new Map(width, height);
Map duplicateMap = new Map(width, height);
// Fill non-sides with random bits
for (int i = 1; i < width - 1; ++i)
{
for (int j = 1; j < height - 1; ++j)
{
Point p = new Point(i, j);
if (m_random.Chance(40))
map.SetTerrainAt(p, TerrainType.Wall);
else
map.SetTerrainAt(p, TerrainType.Floor);
}
}
FillEdgesWithWalls(map);
// For 4 iterators, apply 1stset 1 rules...
// If we're near(1 tile) 5 or more walls
// or close to (2 tiles) 2 or less walls
// we're now a wall
for (int z = 0; z < 4; ++z)
{
// Create a local copy to modify. We need both the old and new values for this calculation
duplicateMap.CopyMap(map);
// Walk tiles, applying rule to local copy
for (int i = 1; i < width - 1; ++i)
{
for (int j = 1; j < height - 1; ++j)
{
Point p = new Point(i, j);
int closeWalls = CountNumberOfSurroundingWallTilesOneStepAway(map, i, j);
int farWalls = CountNumberOfSurroundingWallTilesTwoStepAway(map, i, j);
bool conditionOne = closeWalls >= 5;
bool conditionTwo = farWalls <= 2;
if (conditionOne || conditionTwo)
duplicateMap.SetTerrainAt(p, TerrainType.Wall);
else
duplicateMap.SetTerrainAt(p, TerrainType.Floor);
}
}
// Push our changes out
map.CopyMap(duplicateMap);
}
// For 4 iterators, apply 2nd set of rules...
// If we're near(1 tile) 5 or more walls we're now a wall
for (int z = 0; z < 4; ++z)
{
// Create a local copy to modify. We need both the old and new values for this calculation
duplicateMap.CopyMap(map);
// Walk tiles, applying rule to local copy
for (int i = 1; i < width - 1; ++i)
{
for (int j = 1; j < height - 1; ++j)
{
int closeWalls = CountNumberOfSurroundingWallTilesOneStepAway(map, i, j);
Point p = new Point(i, j);
if (closeWalls >= 5)
duplicateMap.SetTerrainAt(p, TerrainType.Wall);
else
duplicateMap.SetTerrainAt(p, TerrainType.Floor);
}
}
// Push our changes out
map.CopyMap(duplicateMap);
}
FillAllSmallerUnconnectedRooms(map);
GenerateUpDownStairs(map, incommingStairs);
Point stairsUpPosition = map.MapObjects.Where(x => x.Type == MapObjectType.StairsUp).First().Position;
GenerateMonstersAndChests(map, stairsUpPosition, level);
return map;
}