本文整理汇总了C#中Terrain.AddLocation方法的典型用法代码示例。如果您正苦于以下问题:C# Terrain.AddLocation方法的具体用法?C# Terrain.AddLocation怎么用?C# Terrain.AddLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terrain
的用法示例。
在下文中一共展示了Terrain.AddLocation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Construct
/// <summary>
/// This method reads the terrain from xml and forms the terrain using the methods in location class
/// </summary>
/// <param name="fileName"></param>
public override void Construct(Terrain terrain, string fileName)
{
//empty the terrain
ClearTerrain(terrain);
using (XmlReader reader = XmlReader.Create(fileName))
{
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "Location":
ILocation iLoc;
var name = reader["Name"];
var loc = new Location(name);
var markedLoc = new MarkedLocation(loc);
if (reader["ExitLocation"] == "true")
{
iLoc = new ExitLocation(markedLoc);
}
else
{
iLoc = markedLoc;
}
terrain.AddLocation(iLoc);
break;
}
}
}
}
using (XmlReader reader = XmlReader.Create(fileName))
{
ILocation iLoc = null;
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "Location":
var name = reader["Name"];
iLoc = terrain.GetLocation(name);
break;
case "Neigbor":
var directionStr = reader["Direction"];
if (reader.Read())
{
var neigborLocName = reader.Value.Trim();
Directions direction;
Enum.TryParse(directionStr, out direction);
var neigborLocation = terrain.GetLocation(neigborLocName);
if (neigborLocation == null)
throw new Exception("There must be a location already defined by the name {0}" + neigborLocation);
iLoc.AddNeighbor(terrain.GetLocation(neigborLocName), direction);
}
break;
}
}
}
}
}
示例2: Construct
public override void Construct(Terrain terrain, string fileName)
{
var tempTerrain = new Terrain();
ExploreStrategy.Construct(tempTerrain, fileName);
foreach (var location in tempTerrain)
{
terrain.AddLocation(new AdvancedLocation(location));
}
ClearTerrain(terrain);
using (XmlReader reader = XmlReader.Create(fileName))
{
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "Location":
ILocation location = LocationFactory.CreateAdvancedLocation(reader["Name"], reader["Type"]);
location.BriefDescription = reader["BriefDescription"];
terrain.Locations.Add(location);
break;
}
}
}
}
using (XmlReader reader = XmlReader.Create(fileName))
{
ILocation iLoc = null;
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "Location":
var name = reader["Name"];
iLoc = terrain.GetLocation(name);
break;
case "Neigbor":
var directionStr = reader["Direction"];
if (reader.Read())
{
var neigborLocName = reader.Value.Trim();
Directions direction;
Enum.TryParse(directionStr, out direction);
var neigborLocation = terrain.GetLocation(neigborLocName);
if (neigborLocation == null)
throw new Exception("There must be a location already defined by the name {0}" +
neigborLocation);
iLoc.AddNeighbor(terrain.GetLocation(neigborLocName), direction);
}
break;
case "Item":
if (reader.Read())
{
var item = ItemFactory.CreateItem(reader.Value.Trim());
iLoc.DropItem(item);
}
break;
}
}
}
}
}