当前位置: 首页>>代码示例>>C#>>正文


C# Terrain.GetLocation方法代码示例

本文整理汇总了C#中Terrain.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# Terrain.GetLocation方法的具体用法?C# Terrain.GetLocation怎么用?C# Terrain.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Terrain的用法示例。


在下文中一共展示了Terrain.GetLocation方法的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;
                        }
                    }
                }
            }
        }
开发者ID:akrem1st,项目名称:Assignment2d,代码行数:67,代码来源:PlayerAutoExploreStrategy.cs

示例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;
                        }
                    }
                }
            }
        }
开发者ID:akrem1st,项目名称:Assignment2d,代码行数:69,代码来源:MultiCreatureAndExploreStrategy.cs


注:本文中的Terrain.GetLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。